Regex Pain

Since Regular Expressions give me headache, I’m writing this so that I remember what the hell things are.

^ = Start of line

$ = End of line

\s = space

\S = non space

| = or

* = 0 or more eg \s* = 0 or more spaces

+ = 1 or more eg \s+ = 1 or more spaces

. = anything eg .* = 0 or more anything

If you want to match something and give it a name is (?<name>…) where … is the regular expression

eg:Action: (?<action>\S+(\s\S+)*)\s+(User: (?<user>.*),.*)*\.\\(?<file>.+)
 

 

 

 

Advertisements

One Response to Regex Pain

  1. Ben says:

    Hey John,

    Check out RegexCoach at http://www.weitz.de/regex-coach/. I find it handy for checking Regex in real-time. Also you might want to print off a copy of http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/ again very useful to have on standby, as are the other cheat sheets up there.

    Hope they help 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s