Regular Expression

S

Shawn B.

Greetings,

Given the following string:

eid=6;mid={S:mid};peid={S:peid};pname={S:pname};;happy={R:happy}


What regular expression would I write to match the ";" but not the ";;". I
want to write a replace regex to replace the ";" with another character and
the ";;" with a ";".


Thanks,
Shawn
 
S

Shawn B.

(?<!;);(?!;)
should match only single ";".

Thanks. I have a question, is the ! a not operator? It looks like you are
actually saying "match ; where no ; appears before or after" ? I'm just
trying to get more expressive with my expressions and didn't ever think to
try it this way. Thanks for the help.


Thanks,
Shawn
 
M

MasterGaurav \(www.edujini-labs.com\)

(?<!;);(?!;)

Not quite sure but I think it will fail for:

"A;"

For the specific case given by Shawn where ';' does not appear at start or
end, how about:

[^;];[^;]

Why do we need to have a negative lookbehind ('<')?

Again, not quite sure but I think have look-aheads or look-behinds would be
costlier... correct me if I am wrong.


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 
C

Christof Nordiek

MasterGaurav (www.edujini-labs.com) said:
Not quite sure but I think it will fail for:

"A;"

For the specific case given by Shawn where ';' does not appear at start or
end, how about:


Do you mean, the ';' in "A;" shouldn't be matched?
I'm not sure, but Shawn will know.

[^;];[^;]

Why do we need to have a negative lookbehind ('<')?

Again, not quite sure but I think have look-aheads or look-behinds would
be costlier... correct me if I am wrong.
Your not quite sure? I'm absolute not sure ;-)
Since there is a semantic difference, first it should be decided, what is
the correct expression.
If the difference doesn't matter, (f.e. because ";" at beginning or end
could not occur), then we may look, what has better performance.

Christof
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top