Changeparticular characters in a string by using regular expressions ...
Hello Everyone,
I am trying to write a function by using oracles regular expression function REGEXP_REPLACE but I could not succed till now.
My problem as follows, I have a text in a column for example let say 'sdfsdf Sdfdfs Sdfd' I want replace all s and S characters with X and make the text look like 'XdfXdf XdfdfX Xdfd'.
Is it possible by using regular expressions in oracle ?
Can you give me some clues ?
Thank you
SSU wrote:
Hello Everyone,
I am trying to write a function by using oracles regular expression function REGEXP_REPLACE but I could not succed till now.
My problem as follows, I have a text in a column for example let say 'sdfsdf Sdfdfs Sdfd' I want replace all s and S characters with X and make the text look like 'XdfXdf XdfdfX Xdfd'.
Is it possible by using regular expressions in oracle ?
Can you give me some clues ?
Thank you
SQL> SELECT
2 regexp_replace('sdfsdf Sdfdfs Sdfd','s|S','X') from dual;
REGEXP_REPLACE('SD
XdfXdf XdfdfX XdfdRegards,
Achyut
Similar Messages
-
String extract using regular expression
Hi
I have text like this "<a>45</a><ct>Hi</ct><R>45 85</R><H>Here</H>" .I want to extract using regular expression or any techniques the text between <R> and </R> also need to replace the space with pipe between 45 and 85 like "45|85"
Edited by: vishnu prakash on Mar 2, 2012 4:42 AMHi,
Here's one way:
REPLACE ( REGEXP_REPLACE ( txt
, '.*<R>(.*)</R>.*'
, '\1'
, '|'
)This assumes there is only one <R> tag in txt.
Always say which version of Oracle you're using. The expression above will work in Oralce 10 and up, but starting in Oracle 11 you can use REGEXP_SUBSTR rather than the less intuitive REGEXP_REPLACE.
Edited by: Frank Kulash on Mar 2, 2012 7:48 AM -
String replace using regular expressions
I'm not very good at regular expressions, but I would like my script to replace
<a href="somepage.html">
by
<a href="event:somepage">
How do I do this? Thanks in advance!Replacing a string that matches a certain pattern with another string is one of the more common RegEx tasks. There is documentation on using them here:
http://livedocs.adobe.com/flex/3/html/help.html?content=12_Using_Regular_Expressions_01.ht ml
hth,
matt horn
flex docs -
Splitting html ul tags and their content into string arrays using regular expression
<ul data-role="listview" data-filter="true" data-inset="true">
<li data-role="list-divider"></li><li><a href="#"><h3>
my title
</h3><p><strong></strong></p></a></li>
</ul>
<ul data-role="listview" data-filter="true" data-inset="true">
<li data-role="list-divider"></li><li>test.</li>
</ul>
I need to be able to slip this html into two arrays hold the entire <ul></ul> tag. Please help.
Thanks.Hi friend.
This forum is to discuss problems of C# development. Your question is not related to the topic of this forum.
You'll need to post it in the dedicated Archived Forums N-R > Regular Expressions
for better support. Thanks for understanding.
Best Regards,
Kristin -
String Manipulation using Regular Expression
Hello Guys,
I stuck in a situation wherein I want to extract specific data from a column of the table .
Below are the values for a particular column wherein I want to ignore values along with bracket which are in bracket and which are like .pdf,.doc .
Tris(dibenzylideneacetone)dipalladium (0) 451CDHA.pdf
AM57001A(ASRM549CDH).DOC
AM23021A Identity of sulfate (draft)
PG-1183.E.2 (0.25 mg FCT)
AS149656A (DEV AERO APPL HFA WHT PROVENTIL)
Stability report (RSR) Annex2 semi-solid form (internal information)
TSE(Batch#USLF000332)-242CDH, Lancaster synthesis.pdf
TR3018520A Addendum 1 (PN 3018520)
AM10311A Particle size air-jet sieving (constant sieving) (draft)
ASE00099B Addendum (PN E000099) 90 mesh
AM37101_312-99 (Z11c) Palladium by DCP.doc
PS21001A_1H-NMR.doc (PN 332-00)
AM68311A (Q-One CP 33021.02) Attachment
AM68202-1A (BioReliance no. 02.102006) Attachment
I want below output for above values for column
Trisdipalladium451CDHA
AM57001A
AM23021A Identity of sulfate
PG-1183.E.2
Thanks in advanceLike this?
SQL> with t
2 as
3 (
4 select 'Tris(dibenzylideneacetone)dipalladium (0) 451CDHA.pdf' str from dual
5 union all
6 select 'AM57001A(ASRM549CDH).DOC' str from dual
7 union all
8 select 'AM23021A Identity of sulfate (draft)' str from dual
9 union all
10 select 'PG-1183.E.2 (0.25 mg FCT)' str from dual
11 union all
12 select 'AS149656A (DEV AERO APPL HFA WHT PROVENTIL)' str from dual
13 union all
14 select 'Stability report (RSR) Annex2 semi-solid form (internal information)' str from dual
15 union all
16 select 'TSE(Batch#USLF000332)-242CDH, Lancaster synthesis.pdf' str from dual
17 union all
18 select 'TR3018520A Addendum 1 (PN 3018520)' str from dual
19 union all
20 select 'AM10311A Particle size air-jet sieving (constant sieving) (draft)' str from dual
21 union all
22 select 'ASE00099B Addendum (PN E000099) 90 mesh' str from dual
23 union all
24 select 'AM37101_312-99 (Z11c) Palladium by DCP.doc' str from dual
25 union all
26 select 'PS21001A_1H-NMR.doc (PN 332-00)' str from dual
27 union all
28 select 'AM68311A (Q-One CP 33021.02) Attachment' str from dual
29 union all
30 select 'AM68202-1A (BioReliance no. 02.102006) Attachment' str from dual
31 )
32 select str
33 , regexp_replace(str, '(\([^)]+\))|(\..{3})') str_new
34 from t;
STR STR_NEW
Tris(dibenzylideneacetone)dipalladium (0) 451CDHA.pdf Trisdipalladium 451CDHA
AM57001A(ASRM549CDH).DOC AM57001A
AM23021A Identity of sulfate (draft) AM23021A Identity of sulfate
PG-1183.E.2 (0.25 mg FCT) PG-1183
AS149656A (DEV AERO APPL HFA WHT PROVENTIL) AS149656A
Stability report (RSR) Annex2 semi-solid form (internal information) Stability report Annex2 semi-solid form
TSE(Batch#USLF000332)-242CDH, Lancaster synthesis.pdf TSE-242CDH, Lancaster synthesis
TR3018520A Addendum 1 (PN 3018520) TR3018520A Addendum 1
AM10311A Particle size air-jet sieving (constant sieving) (draft) AM10311A Particle size air-jet sieving
ASE00099B Addendum (PN E000099) 90 mesh ASE00099B Addendum 90 mesh
AM37101_312-99 (Z11c) Palladium by DCP.doc AM37101_312-99 Palladium by DCP
PS21001A_1H-NMR.doc (PN 332-00) PS21001A_1H-NMR
AM68311A (Q-One CP 33021.02) Attachment AM68311A Attachment
AM68202-1A (BioReliance no. 02.102006) Attachment AM68202-1A Attachment
14 rows selected. -
Using Regular Expressions To Remove Characters JDK 1.4
I want to write a regular expression to remove all commas in a string of text.
string is:
1,000
or 1,000,000
I want it to return 1000 and 1000000.
I have tried some but I am just starting with Regular Expressions.
Please Help!Try this tutorial: Linux : Education : Tutorials
Using regular expressions
David Mertz
President, Gnosis Software, Inc.
September 2000
http://www-105.ibm.com/developerworks/education.nsf/linux-onlinecourse-bytitle/6C2B4863702F592B8625696200589C5B?OpenDocument -
Using Regular Expressions to replace Quotes in Strings
I am writing a program that generates Java files and there are Strings that are used that contain Quotes. I want to use regular expressions to replace " with \" when it is written to the file. The code I was trying to use was:
String temp = "\"Hello\" i am a \"variable\"";
temp = temp.replaceAll("\"","\\\\\"");
however, this does not work and when i print out the code to the file the resulting code appears as:
String someVar = ""Hello" i am a "variable"";
and not as:
String someVar = "\"Hello\" i am a \"variable\"";
I am assumming my regular expression is wrong. If it is, could someone explain to me how to fix it so that it will work?
Thanks in advance.Thanks, appearently I'm just doing something weird that I just need to look at a little bit harder.
-
Removing Duplicate Characters in a String without using a Hashset
I was wondering if anyone knew a way of removing duplicate characters in a string without using a Hashset.
I want to go from
helloworld -> helowrdokay, here it is
1) use a loop, look through each character in the original string
2) look at the new string, if this character exist, don't add it, otherwise add it.
check out methods in java.lang.String -
Format string using Regular Expression
Input string output format...
SELECT q'<select ab_c "ABC", efg "EFG" from dual>' str FROM DUAL
Output:
STR
select ab_c "ABC", efg "EFG" from dual
Required output format using regular expression...
STR
select 'ab_c' "ABC", 'efg' "EFG" from dualRegular expressions have many limitations as parsing tools, and you didn't specify the rules you wanted. This expression puts quotes around the non blank string before a quoted string:
SELECT regexp_replace(q'<select ab_c "ABC", efg "EFG" from dual>',
'([^" ]+)( +"[^ ]*")' , '''\1''\2' ) str FROM DUAL;
STR
select 'ab_c' "ABC", 'efg' "EFG" from dual
{code}
It is not robust - a missing " will confuse it, and you should be using bind variables anyway. -
Trying to use regular expressions to convert names to Title Case
I'm trying to change names to their proper case for most common names in North America (esp. the U.S.).
Some examples are in the comments of the included code below.
My problem is that *retName = retName.replaceAll("( [^ ])([^ ]+)", "$1".toUpperCase() + "$2");* does not work as I expect. It seems that the toUpperCase method call does not actually do anything to the identified group.
Everything else works as I expect.
I'm hoping that I do not have to iterate through each character of the string, upshifting the characters that follow spaces.
Any help from you RegEx experts will be appreciated.
{code}
* Converts names in some random case into proper Name Case. This method does not have the
* extra processing that would be necessary to convert street addresses.
* This method does not add or remove punctuation.
* Examples:
* DAN MARINO --> Dan Marino
* old macdonald --> Old Macdonald <-- Can't capitalize the 'D" because of Ernst Mach
* ROY BLOUNT, JR. --> Roy Blount, Jr.
* CAROL mosely-BrAuN --> Carol Mosely-Braun
* Tom Jones --> Tom Jones
* ST.LOUIS --> St. Louis
* ST.LOUIS, MO --> St. Louis, Mo <-- Avoid City Names plus State Codes
* This is a work in progress that will need to be updated as new exceptions are found.
public static String toNameCase(String name) {
* Basic plan:
* 1. Strategically create double spaces in front of characters to be capitalized
* 2. Capitalize characters with preceding spaces
* 3. Remove double spaces.
// Make the string all lower case
String retName = name.trim().toLowerCase();
// Collapse strings of spaces to single spaces
retName = retName.replaceAll("[ ]+", " ");
// "mc" names
retName = retName.replaceAll("( mc)", " $1");
// Ensure there is one space after periods and commas
retName = retName.replaceAll("(\\.|,)([^ ])", "$1 $2");
// Add 2 spaces after periods, commas, hyphens and apostrophes
retName = retName.replaceAll("(\\.|,|-|')", "$1 ");
// Add a double space to the front of the string
retName = " " + retName;
// Upshift each character that is preceded by a space
// For some reason this doesn't work
retName = retName.replaceAll("( [^ ])([^ ]+)", "$1".toUpperCase() + "$2");
// Remove double spaces
retName = retName.replaceAll(" ", "");
return retName;
Edited by: FuzzyBunnyFeet on Jan 17, 2011 10:56 AM
Edited by: FuzzyBunnyFeet on Jan 17, 2011 10:57 AMHopefully someone will still be able to provide a RegEx solution, but until that time here is a working method.
Also, if people have suggestions of other rules for letter capitalization in names, I am interested in those too.
* Converts names in some random case into proper Name Case. This method does not have the
* extra processing that would be necessary to convert street addresses.
* This method does not add or remove punctuation.
* Examples:
* CAROL mosely-BrAuN --> Carol Mosely-Braun
* carol o'connor --> Carol O'Connor
* DAN MARINO --> Dan Marino
* eD mCmAHON --> Ed McMahon
* joe amcode --> Joe Amcode <-- Embedded "mc"
* mr.t --> Mr. T <-- Inserted space
* OLD MACDONALD --> Old Macdonald <-- Can't capitalize the 'D" because of Ernst Mach
* old mac donald --> Old Mac Donald
* ROY BLOUNT,JR. --> Roy Blount, Jr.
* ST.LOUIS --> St. Louis
* ST.LOUIS,MO --> St. Louis, Mo <-- Avoid City Names plus State Codes
* Tom Jones --> Tom Jones
* This is a work in progress that will need to be updated as new exceptions are found.
public static String toNameCase(String name) {
* Basic plan:
* 1. Strategically create double spaces in front of characters to be capitalized
* 2. Capitalize characters with preceding spaces
* 3. Remove double spaces.
// Make the string all lower case
String workStr = name.trim().toLowerCase();
// Collapse strings of spaces to single spaces
workStr = workStr.replaceAll("[ ]+", " ");
// "mc" names
workStr = workStr.replaceAll("( mc)", " $1 ");
// Ensure there is one space after periods and commas
workStr = workStr.replaceAll("(\\.|,)([^ ])", "$1 $2");
// Add 2 spaces after periods, commas, hyphens and apostrophes
workStr = workStr.replaceAll("(\\.|,|-|')", "$1 ");
// Add a double space to the front of the string
workStr = " " + workStr;
// Upshift each character that is preceded by a space and remove double spaces
// Can't upshift using regular expressions and String methods
// workStr = workStr.replaceAll("( [^ ])([^ ]+)", "$1"toUpperCase() + "$2");
StringBuilder titleCase = new StringBuilder();
for (int i = 0; i < workStr.length(); i++) {
if (workStr.charAt(i) == ' ') {
if (workStr.charAt(i+1) == ' ') {
i += 2;
while (i < workStr.length() && workStr.charAt(i) == ' ') {
titleCase.append(workStr.charAt(i++));
if (i < workStr.length()) {
titleCase.append(workStr.substring(i, i+1).toUpperCase());
} else {
titleCase.append(workStr.charAt(i));
return titleCase.toString();
{code} -
Validate cfinput using regular expression
Hi,
can somebody help me valditing an cfinput field using regular expressions?
First digit must be a number or "R".
Digit 2-15 can be everything without special characters. Digit 2-15 can also be empty.
I try this, but it doesn't work (Sorry I'm a beginner using regex).
<cfinput type="text" name="field1" required="yes" validate="regular_expression" pattern="[0-9Rr][0-9a-zA-Z]*" maxlength="15">
Thank you in advice!
ClaudiaYou haven't told your regex to match the entire string, so it will "pass"
any string that has your match anywhere within it, so like as long as it's
got an R or a digit in it: it's OK.
To tell it to match the entire string, anchor it to the start and end of the
string with ^ and $ respectively.
Regular expression syntax: Using special characters
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a38f -7ffb.html#WSc3ff6d0ea77859461172e0811cbec0a38f-7fef
Adam -
One for the Tekkies: How to get this output using REGULAR EXPRESSIONS?
How to get the below output using REGULAR EXPRESSIONS??
SQL> ed
Wrote file afiedt.buf
1* CREATE TABLE cus___addresses (full_address VARCHAR2(200 BYTE))
SQL> /
Table created.
SQL> PROMPT Address Format is: House #/Housename, street, City, Zip Code, COUNTRY
House #/Housename, street, City, Zip Code, COUNTRY
SQL> INSERT INTO cus___addresses VALUES('1, 3rd street, Lansing, MI 49001, USA');
1 row created.
SQL> INSERT INTO cus___addresses VALUES('3B, fifth street, Clinton, OK 74103, USA');
1 row created.
SQL> INSERT INTO cus___addresses VALUES('Rose Villa, Stanton Grove, Murray, TN 37183, USA');
1 row created.
SQL> SELECT * FROM cus___addresses;
FULL_ADDRESS
1, 3rd street, Lansing, MI 49001, USA
3B, fifth street, Clinton, OK 74103, USA
Rose Villa, Stanton Grove, Murray, TN 37183, USA
SQL> The REG EXP query shouLd output the ZIP codes: i.e. 49001, 74103, 37183 in 3 rows.Edited by: user12240205 on Jun 18, 2012 3:19 AMHi,
user12240205 wrote:
... Frank, ʃʃp's method, I understand. But your method, although correct, I find it difficult to understand.
Could you explain how you did this?? What does '.*(\d{5})\D*' and '\1' mean???
Your method is better because it uses only ONE reg expression function. ʃʃp's uses 2.In Oracle 10.2 (I believe) and higher, '\d' is equivalent to '[[:digit:]]', and '\D' is equivalent to '[^[:digit:]]'. I find '\d' and '\D' easier to type, but there's nothing wrong with using '[[:digit:]]' and '[^[:digit:]]'.
'.*' means "0 or more of any character".
'\D*' means "0 or more non-digits".
The whole expression, '.*(\d{5})\D*' means:
a. 0 or more characters (any characters)
b. 5 digits
c. 0 or more non-digits.
'\1' is a Backreference . It means the sub-string that matched the pattern after the 1st '(', up to (but not including) its matching ')'. In this case, that means the sub-string that matched '\d{5}', or b. using the explanation immediately above.
So the entire REGEXP_REPLACE call means "When you see a sub-string consisting of a., follwed immediately by b., followed immedately by c., replace that sub-string with b. alone." -
Using regular expressions in java
Does anyone of you know a good source or a tutorial for using regular expressions in java.
I just want to look at some examples....
Thanksthanks a lot... i have one more query
Boundary matchers
^ The beginning of a line
$ The end of a line
\b A word boundary
\B A non-word boundary
\A The beginning of the input
\G The end of the previous match
\Z The end of the input but for the final terminator, if any
\z The end of the input
if i want to use the $ for comparing with string(text) then how can i use it.
Eg if it is $120 i got a hit
but if its other than that if should not hit. -
How to define a regular expression using regular expressions
Hi,
I am looking for some regular expression pattern which will identify a regular expression.
Also, is it possible to know how does the compile method of Pattern class in java.util.regex package work when it is given a String containing a regex. ie. is there any mechanism to validate regular expression using regular expression pattern.
Regards,
AbhisekI am looking for some regular expression pattern which will identify a regular
expression. Also, is it possible to know how does the compile method of
Pattern class in java.util.regex package work when it is given a String
containing a regex. ie. is there any mechanism to validate regular
expression using regular expression pattern.It is impossble to recognize an (in)valid regular expression string using a
regular expression. Google for 'pumping lemma' for a formal proof.
kind regards,
Jos -
Using regular expressions to get a customized output
Hi,
I have a string/varchar variable with the data ',a,b,c,' in it.
I want the display as follows:
a
b
c
I would like to get the similar output using regular expressions.
How do I get this output using REGEXP_REPLACE or REGEXP_SUBSTR?
Please do the needful.
Thanks & Regards,
RakshitI remember that, however if we look closer, that one has a little flaw: The 2nd row should be null, because ",," indicates an empy field. The MODEL clause solution works just fine in this case:
with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)
-- end of sample data
SELECT col_new
FROM t
MODEL
PARTITION BY (ROWNUM rn)
DIMENSION BY (0 dim)
MEASURES(col1, col1 col_new)
RULES ITERATE(99) UNTIL (ITERATION_NUMBER = LENGTH(REGEXP_REPLACE(col1[0], '[^,]')))
(col_new[ITERATION_NUMBER] = REPLACE(REGEXP_SUBSTR(col1[0], '(^|,)[^,]*', 1, ITERATION_NUMBER+1), ','))
COL_NEW
aaaa
bbbb
cccc
dddd
eeee
ffff
7 Zeilen ausgewählt.Update: I had this nagging feeling that I missed something, and there it was. If you want to see what the problem with my solution is, change the example to
with t as (select ',aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)So I went back and tried to fix BlueShadows approach. Here it is:
with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' txt from dual)
-- end of sample data
SELECT REPLACE(REGEXP_SUBSTR(',' || txt, ',[^,]*', 1, level), ',') col_new
FROM t
CONNECT BY level <= length(regexp_replace(txt,'[^,]*'))+1
;C.
Maybe you are looking for
-
Example addons that are currently working include no-script and downloadthemall. Both addons are working but do not show up under extensions. I can only see my plugins, such as java, realplayer, shockwave etc. It's very annoying when trying to acess
-
Could my video card be the root of all these problems???
heres the problem: dual 1.0ghz mdd with a rage 128 pro video card. the computer has a clean install of os x 10.5.8 but dvd player wont work (it says it cant find a valid video device), vlc will play audio only, and quicktime will only play a few sele
-
How to use Message FIlter to log postfix authenticated sender header
I'm trying to log the username from the postfix authenticated sender header information. Here is an example of the header: Received: from [123.123.123.123] (client.domain.edu [234.234.234.234]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/25
-
Hi, I've got my RSS feed linked to a JPEG image that I know is far larger than 300 x 300 pixels (minimum), but it still doesn't show up when my podcast is downloaded from the iTunes store. How can I get that to work?
-
My wired keyboard will not work
Wired aluminum Apple keyboard with number pad is not working. When I forced a restart it started looking for a Bluetooth keyboard and would not stop. Got that to stop but keyboard does not work. Tried shutting down, unplugging everything and starting