Thursday, June 11, 2015

Regular Expression notes

I think I need to collect all my regular expression notes here to help myself and anyone who need it, I might not be smart enough to understand how it work thoroghly by just read tutorial, so I will collect all examples here to help:

1. Remove control characters and space (the red mark is a space) (oracle example):
select 'asdfo'||chr(9)||'dsu iue', regexp_replace('asdfo'||chr(9)||'dsu iue', '[[:cntrl:] ]','') from dual

2. The following will match utill second occurence, *? is lazy qualifier so it will stop when it find the next foo:
foo.*?(foo)
string: goo foo goo goo foo goo foo goo foo goo fo
3. The following will match utill last occurence, as we removed the lazy qualifier from #2, it will stop when it find the last foo: 
foo.*(foo)
string: goo foo goo goo foo goo foo goo foo goo fo