RegEx for \x###

A

Arthur Dent

Hello all, i am trying to write a regex to find escaped characters in a
string of the form "\x009" ...
to parse strings that look something like this... "My dog jumps\x013\x010"

I had that working fine, with the regex "\\[x]\d{3}"

Now i wanted to extend it so that it would NOT count them when the leading
slash is itself, preceeded by a slash (escaped).
so this sentence would NOT match... "My dog jumps\\x013\\x010"

This is where i ran into problems.
I tried doing this... [^\\]?\\[x]\d{3} but the problem is then that it
includes the preceeding, non-slash character in any matches, which i dont
want.So in this, "My dog jumps\x013\x010" the matches returned would be
"s\x013" and "\x010". I do not want that "s" on the front, but i need to
make sure the slash isnt doubled (escaped).

Any help with my regex? Thanks in advance,
- Arthur.
 
R

rowe_newsgroups

Hello all, i am trying to write a regex to find escaped characters in a
string of the form "\x009" ...
to parse strings that look something like this... "My dog jumps\x013\x010"

I had that working fine, with the regex "\\[x]\d{3}"

Now i wanted to extend it so that it would NOT count them when the leading
slash is itself, preceeded by a slash (escaped).
so this sentence would NOT match... "My dog jumps\\x013\\x010"

This is where i ran into problems.
I tried doing this... [^\\]?\\[x]\d{3} but the problem is then that it
includes the preceeding, non-slash character in any matches, which i dont
want.So in this, "My dog jumps\x013\x010" the matches returned would be
"s\x013" and "\x010". I do not want that "s" on the front, but i need to
make sure the slash isnt doubled (escaped).

Any help with my regex? Thanks in advance,
- Arthur.

The (?<= ) group will match a prefix, but it won't include it in the
results. With that said I believe your Regex should become:

(?<=[^\\])?\\[x]\d{3}

By the way, I tested this with Expresso, which is a great tool for
Regex.

Thanks,

Seth Rowe
 
A

Arthur Dent

Thanks for the great tip - that Expresso tool IS way cool!

Your regex worked fine, too. Though, thanks to Expresso, ;) ...
i was able to pare it down even a little further...

from (?<=[^\\])?\\[x]\d{3}
to (?<![\\])\\[x]\d{3}

Thanks for the great info.... CheerZ!


rowe_newsgroups said:
Hello all, i am trying to write a regex to find escaped characters in a
string of the form "\x009" ...
to parse strings that look something like this... "My dog
jumps\x013\x010"

I had that working fine, with the regex "\\[x]\d{3}"

Now i wanted to extend it so that it would NOT count them when the
leading
slash is itself, preceeded by a slash (escaped).
so this sentence would NOT match... "My dog jumps\\x013\\x010"

This is where i ran into problems.
I tried doing this... [^\\]?\\[x]\d{3} but the problem is then that it
includes the preceeding, non-slash character in any matches, which i dont
want.So in this, "My dog jumps\x013\x010" the matches returned would be
"s\x013" and "\x010". I do not want that "s" on the front, but i need to
make sure the slash isnt doubled (escaped).

Any help with my regex? Thanks in advance,
- Arthur.

The (?<= ) group will match a prefix, but it won't include it in the
results. With that said I believe your Regex should become:

(?<=[^\\])?\\[x]\d{3}

By the way, I tested this with Expresso, which is a great tool for
Regex.

Thanks,

Seth Rowe
 

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

Similar Threads

How to get the text with regex? 1
regex "%s" and how to escape the % 2
Regex value between brackets 2
Regex in C# 4
Regex match on all words? 3
Regex help 2
Quick regex question 7
Regex Issues 7

Top