Replace a single character with Regular Expressions
Hello,
I would like to replace a character by a string.
For example, "12<15" ---> "12&#xx;15"
To that aim, I use the following code:
String s = "12<15";
s.replaceAll("<", "&#xx;");Unfortunately, it doesn't work. The string is not altered.
What's the bug?
Thanks for your help.
try
s = s.replaceAll(.....)
Rgds
Similar Messages
-
SQL Advice - Replace an OR maybe with regular expression?
Hello everyone,
I have a little question. This one is bothering me for weeks now and I was wondering if any of you have another idea for this.
Imagine the following table. It's a very stupid table. But look at the sample data. I reproduced the question that I have with the 3 records.
CREATE TABLE departments
dpt_id NUMBER(10),
dpt_name VARCHAR2(100)
INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGER');
INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGERIA');
INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGER.0001');
SELECT *
FROM departments
WHERE (dpt_name = 'NIGER' OR dpt_name LIKE 'NIGER.%');If I use a LIKE NIGER%, I retrieve also NIGERIA (which I don't want). So, instead, I use this OR combination and it works well. But I was wondering if it is doable without this OR.
Thanks,Hi,
if you know the characters you will allow follwoing Niger, eg. dot and digits only you might consider using translate
SELECT *
FROM departments
WHERE translate (dpt_name, 'A0123456789.', 'A') like 'NIGER'
but this will match N9IGER too.
also regexp is possible
SELECT *
FROM departments
WHERE regexp_like (dpt_name, 'NIGER[^[:alpha:]]*$')Regards
Edited by: chris227 on 11.08.2012 09:38 -
Grouping & Back-references with regular expressions on Replace Text window
I really appreciate the inclusion of the Regular Expressions in the search & replace feature. One thing I am missing is back-references in the replacement expression. For instance, in the unix tools vi or sed, I might do something like this:
s/\(firstPart\) \(secondPart\) \(oldThirdPart\)/\2 \1 newThirdPart/g
which would allow me to switch the places of firstPart and secondPart, and totally replace thirdPart. If grouping and back-references are already present in the Replace Text window, how does one correctly invoke them?duplicate of Grouping & Back-references with regular expressions on Replace Text window
-
Assistance with Regular Expression and Tcl
Assistance with Regular Expression and Tcl
Hello Everyone,
I recently began learning Tcl to develop scripts for automating network switch deployments.
In my script, I want to name the device with a location and the last three octets of the base mac address.
I can get the Base MAC address by :
show version | include Base
Base ethernet MAC Address : 00:00:00:DB:CE:00
And I can get the last three octets of the MAC address using the following regular expression.
([0-9a-f]{2}[:-]){2}([0-9a-f]{2}$)
But I have not been able to figure out how to call the regular expression in the tcl script.
I have checked several resources but have not been able to figure it out. Suggestions?
Ultimately, I want to set the last three octets to a variable (something like below) and then call the variable when I name the switch.
set mac [exec "sh version | i Base"] (include the regular expression)
ios_config "hostname location$mac"
Thanks for any assistance in advance.
ChrisThis worked for me.
Switch_1(tcl)#set result [exec show ver | inc Base]
Base ethernet MAC Address : 00:1B:D4:F8:B1:80
Switch_1(tcl)#regexp {([0-9A-F:]{8}\r)} $result -> mac
1
Switch_1(tcl)#puts $mac
F8:B1:80
Switch_1(tcl)#ios_config "hostname location$mac"
%Warning! Hostname should contain at least one alphabet or '-' or '_' character
locationF8:B1:80(tcl)# -
How do I find & replace a single character?
Am using Adobe Acrobat Pro....
The find/replace box pull down has "Whole Words Only" checked and I cannot uncheck it. How can I find and replace a single character throughout a document?That's just how it works. You can "find" anything, but you can only "replace" whole words. As soon as you click to open the "replace" section of the dialog the search settings are locked into their basic states, even if you don't enter a replacement string (but that part's a bug).
The simple answer is that you cannot replace all instances of one character using Acrobat's inbuilt tools. You're expected to edit the document outside of PDF and recreate it. -
How to search with regular expression
I make pdx files so that I can search text quickly. But Acrobat doesn't provide a way to search with regular expression. I'm wondering if there is a way that I don't know to search for regular expression in Acrobat Pro 9?
First, Acrobat must "mount" the PDX.
As "Find" does not use the cataloged index, use Shift+Ctrl+F to open the advanced search dialog.
It may be helpful to first enter Acrobat Preferences and for the Search category tick "Always use advanced search options".
Back to the Search dialog - use the drop down menu for "Look In" to pick "Select Index" then, if no PDXs show, click the Add button.
In the Open Index File dialog, browse to the location of the desired PDX and select it.
OK out and use "Return results containing" to pick a "Match ..." requirement or Boolean.
To become familiar with query syntax, for Acrobat, it is good to review Acrobat Help.
http://help.adobe.com/en_US/Acrobat/9.0/Professional/WS58a04a822e3e50102bd615109794195ff-7 c4b.w.html
Be well... -
Problem with Regular Expression
Hi There!!
I have a problem with regular expression. I want to validate that one word and second word are same. For that I have written a regex
Pattern p=Pattern.compile("([a-z][a-zA-Z]*)\\s\1");
Matcher m=p.matcher("nikhil nikhil");
boolean t=m.matches();
if (t)
System.out.println("There is a match");
else
System.out.println("There is no match");
The result I am getting is always "There is no match
Your timely help will be much appreciated.
RegardsRam wrote:
ErasP wrote:
You are missing a backward slash in the regex
Pattern p = Pattern.compile("([a-z][a-zA-Z]*)\\s\\1");
But this will fail in this case.
Matcher m = p.matcher("Nikhil Nikhil");It is the reason for that *[a-z]*.The OP had [a-z][a-zA-Z]* in his code, so presumably he know what that means and wants that String not to match. -
Get the string between li tags, with regular expression
I have a unordered list, and I want to store all the strings between the li tags (<li>.?</li>)in an array:
<ul>
<li>This is String One</li>
<li>This is String Two</li>
<li>This is String Three</li>
</ul>
This is what have so far:
<li>(.*?)</li>
but it is not correct, I only want the string without the li tags.
Thanks.No one?
Anoyone here experienced with Regular Expression? -
[CC] Search&Replace: Bug only with Regular Expressions
Can you confirm the following behaviour/bug?
Steps to reproduce:
1 Create a new document in DW CC
2 Enter that text in the source code view:
<p>€</p>
3 Open Search&Replace
Field Search in: Current document
Field Search: Text
Field Search (3rd Field): €
Start Search
Result: As expected the "€" is found.
4 [x] Regular Expressions
Start Search
Result: "€" isn't found
Can you reproduce that?
Do you regard that as a bug like me?
If not, why please?
Do you think it is technically impossible for the developers to solve the task?
Do you think the developers forgot to gray out "text" in the choice box and allow regular expressions only in source code?
Thanks.Nice that you like the nick
Sure, I know that I can file a feature wish.
But my main interest in this forum is to know, what other users think about certain features, why they think so, which they miss, which they regard as a bug, ...
When I remember it right, you told me some time ago, that you don't use RegEx.
Than I understand, that everything around that feature is not important for you.
What I like to understand is, why you think the behaviour is logically.
For me it is the opposite.
You get a result with "Scope: Text", "[ ]RegEx".
And you get no result with "Scope: Text", "[x]RegEx".
Incredible strange.
I would appreciate, if you could explain more detailed your view. -
Replace All with Regular Expression
Hi all,
I need a help to replace the String:
to
"<a href=\"1\"">Java Programming</a>"
I was trying to replace with
.replaceAll("\\[\\[*([^\\]]*?)*\\]\\]", "<a href=\"\"></a>")
but I don't know how to separate the parameters values.
Best regardsHi prometheuzz,
you are the one!!
But how I could do to a Srting like this:
Ah, more requirements...
Things are getting a bit messy now:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Main {
public static void main(String[] args) {
String line = "any text any text any text any text any text. "+
"Click - [[Code: 6 Title: Java Programming]]. "+
"any text any text any text any text any text. "+
"- [[C�digo: 2 T�tulo: Sun]] text text "+
"any text any text any text any text any text.";
String newLine = line;
String[] wikiTags = getWikiTags(newLine);
for(String tag : wikiTags) {
String newTag = "<a href=\""+get("(Code:|C�digo:)", " ", tag)+
"\">"+get("(Title:|T�tulo:)", "$", tag)+"</a>";
newLine = newLine.replaceFirst("\\[\\["+tag+"\\]\\]", newTag);
System.out.println(line);
System.out.println(newLine);
public static String[] getWikiTags(String text) {
java.util.List<String> list = new java.util.ArrayList<String>();
Pattern pattern = Pattern.compile("(?<=\\[\\[)(.*?)(?=\\]\\])");
Matcher matcher = pattern.matcher(text);
while(matcher.find()) {
list.add(matcher.group());
return list.toArray(new String[list.size()]);
public static String get(String start, String end, String text) {
Pattern pattern = Pattern.compile("(?<="+start+"\\s)(.*?)(?="+end+")");
Matcher matcher = pattern.matcher(text);
return matcher.find() ? matcher.group() : "#ERROR#";
}Details about regex:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
http://www.regular-expressions.info/java.html
http://java.sun.com/docs/books/tutorial/essential/regex/
>
Thanks a lot for you helpLike I said, it's a bit of a messy solution. See if you can use (a part of) it.
Good luck. -
Replace replace with regular expression possible?
Hi,
Just another regular expression question!
I want to replace the words "AND", "OR", "NOT" in a sentence with the symbols '&', '|', '~' respectively.
Obviously very simple to do with 3 replace statements, just wonder if I can use regexp_replace to achieve it?
CheersHi,
Metacharacter symbols can be used in place of regular expressions.
Here's an implementation scenario:
http://www.oracle.com/technology/obe/obe10gdb/develop/regexp/regexp.htm
Hope it helps.
Regards,
Naveed. -
Replace with regular expression -complex logics
What is the best way to replace input string with following rules:
1. All occurences of two or more sequential Hyphen-symbols (symbol: "-") must be replaced with one hypen. So if input string was "---" then output should be "-". If input was "a-a-a" then output stays as it is.
2. All occurences of two or more sequential Space-symbols (symbol: " ") must be replaced with one Space. So if input string was " " then output should be " ". If input was "a a a" then output stays as it is.
3. After rules 1-2 are applied following rule apply: All occurences of Space-symbol followed immediately after Hypen-symbol or vice vers- hypen followed by Space must be replaced with Hypen. So if input string was " -" or "- " then output should be "-". If input was "a a-a" then output stays as it is.
4. After rules 1-2-3 are apllied following rule must be applied: String start and end symbol may not be Space or Hypen. So if input string was " a" or "-a" or "a " or "a-" then output should be "a".
All rules 1-4 must be apllied to input string.
Example of the replacement logic:
input: 'a aa ---- ss-ee -'
output: 'a aa-ss-ee'
I think i should use function "regexp_replace" somehow.
This solution below doesn't work because it outputs two consecuent hypens "--":
with t as(
select 'a aa ---- ss-ee -' str from dual
select regexp_replace(str, '--','-') a from t;
/*a aa -- ss-ee -*/Can you suggest one neat regular expression for that?SQL>with t as(
2 select 1 id,'a aa ---- ss-ee -' str from dual union
3 select 2, 'a aa -------- ss-ee ---- - - -' str from dual union
4 select 3, '-' str from dual union
5 select 4, '----- -- -a -' str from dual union
6 select 5, '-a-a-a-a----a-a-a-' str from dual
7 )
8 select id,
9 str,
10 trim(trim('-' from regexp_replace(str, '( |-){2,}', '\1'))) new_str,
11 length(str) len,
12 length(trim(trim('-' from regexp_replace(str, '( |-){2,}', '\1')))) new_len
13 from t;
ID STR NEW_STR LEN NEW_LEN
1 a aa ---- ss-ee - a aa ss-ee 19 10
2 a aa -------- ss-ee ---- - - - a aa ss-ee 34 10
3 - 1
4 ----- -- -a - a 13 1
5 -a-a-a-a----a-a-a- a-a-a-a-a-a-a 18 13 -
Replace string with regular expression
I am new to the regular expression. I am just trying to remove double quotes from a string.
My sample string is sql statement(SELECT "SCHEMA"."TABLE1"."COLUMN1", "SCHEMA"."TABLE1"."COLUMN2" FROM "SCHEMA"."TABLE1", "SCHEMA"."TABLE2" WHERE "SCHEMA"."TABLE1"."COLUMN1" = "SCHEMA"."TABLE2"."COLUMN1" );
This is what I came up with.
String s = query.replaceAll("\\.\"", ".").replaceAll("\"\\.", ".").replaceAll("\\s\"", " ").replaceAll("\\s\"", " ").replaceAll("\",", ",").replaceAll("\"\\s", " ");
But I want to optimize this line.
Could anybody tell me how to call replaceAll once with using regular expression instead of calling replaceAll multiple times? Some table or column names can have double quotes, so I want to remove the double quotes without replacing the double quotes which is part of the table or column name.
I'd appreciated it.caesarkim1 wrote:
I am new to the regular expression. I am just trying to remove double quotes from a string.
My sample string is sql statement(SELECT "SCHEMA"."TABLE1"."COLUMN1", "SCHEMA"."TABLE1"."COLUMN2" FROM "SCHEMA"."TABLE1", "SCHEMA"."TABLE2" WHERE "SCHEMA"."TABLE1"."COLUMN1" = "SCHEMA"."TABLE2"."COLUMN1" );
This is what I came up with.
String s = query.replaceAll("\\.\"", ".").replaceAll("\"\\.", ".").replaceAll("\\s\"", " ").replaceAll("\\s\"", " ").replaceAll("\",", ",").replaceAll("\"\\s", " ");
...Note that the following two lines are equivalent:
s = s.replaceAll("a","").replaceAll("b","");
s = s.replaceAll("a|b",""); -
Extended Replace with Regular Expressions
I am trying to figure out how to user regular expressions in
HomeSite 5.5 extended search and replace.
I am trying to find all matches to: <span
class="someClass">FooText</span>
And replace with: <sometag>FooText</sometag>
I have been able to get the find part working with reg ex:
<span class=\"someClass\">*[A-Za-z0-9_
><.="']*</span>
However, I have not been able to figure out what to put in
the replace box. I have tried different combinations of syntax with
"\1" for the first match of the reg ex in the search field, but
nothing has worked.
Can someone help me out with the syntax for what I should
enter in the replace field?SQL>with t as(
2 select 1 id,'a aa ---- ss-ee -' str from dual union
3 select 2, 'a aa -------- ss-ee ---- - - -' str from dual union
4 select 3, '-' str from dual union
5 select 4, '----- -- -a -' str from dual union
6 select 5, '-a-a-a-a----a-a-a-' str from dual
7 )
8 select id,
9 str,
10 trim(trim('-' from regexp_replace(str, '( |-){2,}', '\1'))) new_str,
11 length(str) len,
12 length(trim(trim('-' from regexp_replace(str, '( |-){2,}', '\1')))) new_len
13 from t;
ID STR NEW_STR LEN NEW_LEN
1 a aa ---- ss-ee - a aa ss-ee 19 10
2 a aa -------- ss-ee ---- - - - a aa ss-ee 34 10
3 - 1
4 ----- -- -a - a 13 1
5 -a-a-a-a----a-a-a- a-a-a-a-a-a-a 18 13 -
Match beginning of line with Regular Expression
I'm confused about dreamweaver's treatment of the characters
^ and $ (beginning of line, end of line) in regex searches. It
seems that these characters match the beginning of the file, not
the beginning of the various lines in the file. I would expect it
to work the other way around. A search like:
(^.)
should match every line in the file, so that a find/replace
could be performed at the beginning of each line, like this:
HELLO$1
which would add 'HELLO' at the start of each line in the
file.
Instead, this action only matches the first character of the
file, sticks 'HELLO' in front of it, and then quits (or moves on to
the next file). The endline character $ behaves in a similar
fashion, matching only the end of the file, not the end of each
line.
I've searched, and all the literature about regular
expressions in dreamweaver seems to indicate that I'm expecting the
correct behavior:
www.adobe.com/devnet/dreamweaver/articles/regular_expressions_03.html
quote:
^ Beginning of input or line ^T matches "T" in "This good
earth" but not in "Uncle Tom's Cabin"
$ End of input or line h$ matches "h" in "teach" but not in
"teacher"
Thanks for any insight, folks.Hi Winston,
I am still digesting the material from the regular expression book and will take sometime to become proficient with it.
It seems that using groupCount() to eliminate the unwanted text does not work in this case, since all the lines returned the same value. Ie 3 posted earlier. This may be because the patterns are complex and only a few were grouped together. Otherwise, could you provide an example using the string posted as opposed to a hyperthetic one. In the meantime, at least one solution have been found by defining an additional special pattern “\\A[^%].*\\Z”, before combining / intersecting both existing and the new special pattern to get the best of both world. Another approach that should also work is to evaluate the size of String.split() and only accept those lines with a minimum number of tokens.
Anyhow, I have come a crossed another minor stumbling block in the mean time with the following line, where some hidden characters is preventing the existing pattern from reading it:
o;?Mervan Bay 40 Boyde St 7 br t $250,000 X West Park AE
Below is the existing regular expression that works for other lines with the same pattern but not for special hidden characters such as “o;?”:
\\A([A-Z][a-z]*){1,2} [0-9]{0,4}/?[0-9]{0,4}-?[0-9]{0,4} ([A-Z][a-z]*){1,2} St|Rd|Av|Sq|Cl|Pl|Cr|Gr|Dr|Hwy|Pde|Wy|La [0-9] br [h|u|t] \\$\\d+,\\d+|\\$\\d*\\,\\d+,\\d+ ([A-Z][a-z]*){1,}\\ZIs it possible to come up with a regular expression to ignore them so that this line could be picked up? Would also like to know whether I could combine both the special pattern “\\A[^%].*\\Z” with existing one as opposed to using 2 separate patterns altogether?
Many thanks,
Jack
Maybe you are looking for
-
How Do I change my Iphone 5S order to in store pickup?
What the heck. I placed an order within 24 hours of the iphone 5s debut. The order is of course still stuck in "processing purgatory". My card has been charged for the $10 shipping fee. But not the full price. (I thought orders over $100 were free sh
-
How do you set up a external shared drive for a home network? I have a 1TB external and a 2 TB time capsule. I have a 24" IMAC wich has my Recording Studio soft ware on it. (Pro Tools, Logic Studio) running snow lepoard. I have a 21.5" IMAC which is
-
Why is my mouse making noise through my speakers?
Just got a new mac mini. I hooked it up to my M audio firewire 1814 sound card, and I'm getting noise through the speakers every time I move the mouse, every time an application is loading, every time a web page is loading. I presume it's some kind o
-
Hi All I create a new transaction type in inventory and Check Status Control to enable material status control for this transaction type. but it is not apper on Material Status Control form.also i set the profile option INV: Material Status Support t
-
Ethernet Controller is not working on Satellite L645D-S4030
Basically i got my windows 7 reinstalled on to my laptop because of viruses......Now I have a issue with the Ethernet controller not working, I checked my device manager and there's some kind of yellow dash across the icon......Anyone know what the p