Find Replace Regular Expression [message #1007638] |
Wed, 06 February 2013 20:35 |
Missing name Mising name Messages: 4 Registered: February 2013 |
Junior Member |
|
|
Hello all,
I have an odd problem with regular expressions in the find replace feature of Eclipse. I'm using Juno on Mac OS X 10.7. I am using Classic Eclipse with PDT and Subversive plugins installed.
I have the following options checked:
Direction: Forward
Scope: All
Options: Case_Sensitive, Regular Expressions
Give the following expression in the "Find" field:
\,\s\"
I can replace it with the given expression, essentially adding a new line:
, \r\n\"
However, if I get a little more complex with my expression, the replace function no longer works, even though my expression is matched with better precision:
Find field:
(\,\s\")(?=[A-Z]{2})
Replace With Field is the same as above.
Does anyone have any idea why the lookahead syntax seems to trump the replace functionality of the find/replace features?
|
|
|
Re: Find Replace Regular Expression [message #1007964 is a reply to message #1007638] |
Thu, 07 February 2013 15:14 |
Eclipse User |
|
|
|
Hi,
If I'm reading this correctly (regexp always get messy :-))
> Find field:
> (\,\s\")(?=[A-Z]{2})
>
says to find a ',', whitespace, or double-quote followed by exactly two
alphabetic characters, not three alphas or one alpha but two. Anything
else and it won't match. Then only if it matches will it replace the
',', whitespace, or double-quote while leaving the two alphas there.
Is that what you are actually searching for?
Thanks,
Rich
|
|
|
Re: Find Replace Regular Expression [message #1008043 is a reply to message #1007964] |
Fri, 08 February 2013 16:01 |
Missing name Mising name Messages: 4 Registered: February 2013 |
Junior Member |
|
|
What I'm searching for is:
, "AA
I'm adding a new line between the comma and double quote but only if the two characters after double quote are two upper case characters
IE
{"AA": "some arbitrary data", "name": "some arbitrary data"}, "BB": "other arbitrary data", "name": "more data"}
becomes:
{"AA": "arbitrary data", "name": "arbitrary data",
"BB": "other arbitrary data", "name": "more data"}
The two characters are ISO 3166-a alpha-2 characters (2 character country codes), but I don't want to split on the ISO codes and the "name" field. I want to split on the ISO codes only.
I have some Geospatial data in this format but it's all on one line and the ISO code data is an SVG path to be drawn. The file is 8MB and is a pain to work with as one line so I wanted to split it up to the ~250 lines.
I ended up writing a python script that opened the file, read it all, did the split using the same find replace syntax and wrote the file, but I think Eclipse should have been able to do this.
This made things a lot easier to work with. Instead of eclipse taking 30 seconds to type one character, I was able to edit it like a normal file is expected to behave and not like I was trying to edit an 8MB file on a 386 with only 8MB of memory.
|
|
|
Re: Find Replace Regular Expression [message #1008064 is a reply to message #1008043] |
Fri, 08 February 2013 17:07 |
Eclipse User |
|
|
|
hi,
Yeah that seemed to confuse it, so I changed it to:
Find: (\,\s\")([A-Z]{2})
Replace: , \r\n\"(1)
CaseSensitive: true (requires case-sensitive. If not then [A-Z] still
matches "bb" in addition to "BB").
Rich
|
|
|
Re: Find Replace Regular Expression [message #1008065 is a reply to message #1008043] |
Fri, 08 February 2013 17:11 |
Eclipse User |
|
|
|
Correction:
hi,
Yeah that seemed to confuse it, so I changed it to:
Find: (\,\s\")([A-Z]{2})
Replace: , \r\n\"$2
CaseSensitive: true (requires case-sensitive. If not then [A-Z] still
matches "bb" in addition to "BB").
Rich
|
|
|
|
Re: Find Replace Regular Expression [message #1008306 is a reply to message #1008288] |
Mon, 11 February 2013 20:49 |
Eclipse User |
|
|
|
Hi,
> Each set of parenthesis will increment the variable name used to
> substitute a partial string match with itself, Correct?
That's pretty much true, but you need to read the javadoc on regular
expression groups. They nest i.e. (a(b)c)(d) so $1 is a(b)c and $2 is b
and $3 is d.
Rich
|
|
|
|
Powered by
FUDForum. Page generated in 0.04764 seconds