Scivillage.com Casual Discussion Science Forum

Full Version: Regular Expression tidbits
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
You might spot my voyage of discovery in PHP programming from time to time with any tweaks, additions or breaks (yes, sometimes discovering new things means breaking stuff.)  Occasionally some things that will seem pretty trivial, aren't necessarily as easy as some might think.  So when I actually find a solution, I know I have to note it down somewhere not just for prosperities sake, but purely because at some point in the future I might just have to solve that problem all over again because "I forgot" or didn't note it down.

In any event, I'm going to post a tidbit here every so often which might help others (but will more than likely help my future self)

To start it off:

Regular Expression matches for the position of the Beginning and End of a particular string.

Beginning:
Code:
^()

Ending:
Code:
()$

It uses the '^' beginning of string and '$' end of string characters with a null value enclosed in curved brackets and can be used to match the before first character and after last character of a string.  It's possible to do the same through other means, however sometimes a regex is required that might be parsed from a source that contains multiple lines with newline characters and that breaks any use of '.' (an alias that matches any character apart from newline) 

Incidentally a handy site for working out Regex patterns is www.regex101.com