Regular Expression String Parsing

URI RegExp

parse_url RegExp

^(?P<scheme>[^:]*:?[^a-z]*)(?P<userpass>(?P<user>[^:@/]*):?(?P<pass>[^:@/]*)@*)(?P<host>[^/]*)(?P<path>[^?#]*)\??(?P<query>\?[^#]*)(?P<fragment>.*)$

^(?P<scheme>[^:]*:?[^a-z]*)
(?P<userpass>(?P<user>[^:@/]*):?(?P<pass>[^:@/]*)@*)
(?P<host>[^/]*)
(?P<path>[^?#]*)\??
(?P<query>\?[^#]*)
(?P<fragment>.*)$

Line Filtering

Match any line (including line ending) that does NOT contain the string “skip me” with word boundaries:

(?!.*\bskip me\b).*\r\n

Delete all lines that don’t start with “— (nnnn)” or have the word Stream or AuthorizationManager

(^((?!(-- \([0-9]+\))).)*\n|^.+?Stream.+\n|^.+?AuthorizationManager.+\n)
[]

Delete lines that don’t match RegEx:

^((?!(REGEX1|REGEX2)).)*\n
[]

Delete lines with matching RegEx:

^.+?(REGEX1|REGEX2).+\n
[]

String Formatting

Alphanumeric – Wikipedia

Replace double-quoted string with single-quoted string

"([\w ]*)"
'$1'

Make String AlphaNumeric and Uppercase The First Letter

[^a-z0-9]+([a-z]?)
\u$1

Removing extra white-space from the end of all lines

[\t ]+\n
\n

Reformat all phone numbers to 123-456-7890

\({0,1} {0,1}([0-9]{3}) {0,1}[)/.-]{0,1} {0,1}([0-9]{3}) {0,1}[/.-]{0,1} {0,1}([0-9]{4})
$1-$2-$3

With a URL replace slashes with ampersands and separate the the 1st and 2nd letters with a equal sign.

/([a-z])(.+?)(?=/)
&$1=$2

CSV Timetable Parse?

([0-9-]{10})\t([0-9:]{4,5}\t[0-9:]{4,5}\t[0-9:]{4,5})\t([0-9.]{4,5})\t([A-Z]{2,4}[0-9]{2}-[0-9]{4})
$4\t$1\t$3 Hour

Doxigen Fixes

Fix badly nested @fn.

^\t{0,2}\/\*{1,2} {0,2}@fn.?([a-zA-Z]+.*)
\t/**\n\t * @fn\t\t$1

Fix badly formatted elements.

^\t{0,1} {0,3}\*{1,2}@(.+)
\t * @$1

Fix badly closed comment blocks.

^(\t{0,2} {0,3}\*+?/)
\t */

Key

[] represents an empty string or null value