Jump to content

Using Regular Expressions

Regular expression is a powerful system for searching and manipulating text. It is very widely used and is implemented in most modern programming languages. This means that while it is initially quite difficult to understand there is no shortage of tutorials, tools and sample expressions. One good site for testing your regular expressions is http://regex101.com/. On this site you copy your sample values into one text box and develop your regular expression in another text box, and you see the result as you type.

Please note that regular expressions in Simplebim are by default ‘greedy’ and if you want to use a non-greedy logic you must specify this in your expression.

Here are some examples to get you started. You can also contact us at support@simplebim.com if you have a case that you can’t figure out on your own. When you ask for support, please give an example of a string your want to process and the expected outcome from that example string. We will then try to create the correct regular expression for you.

Regular ExpressionOriginal TextSelected TextComments
^(.*?):Basic Wall:EXT-1:2672323Basic WallThis reads: from the beginning of the text, select all characters until you find the first colon.
:(.*?):Basic Wall:EXT-1:2672323EXT-1This reads: from the first colon select all characters until you find the second colon
:(\d{0,})$Basic Wall:EXT-1:26723232672323This reads: from the end of the text, select all numbers until you find the last colon
^(\S{1,})(?:-|_)ABC-123
ABC_123
ABC
ABC
This reads: from the beginning of the text, select one or more characters until you find the first dash or underscore
(?:-|_)(\S{1,})$ABC-123
ABC_123
123
123
This reads: from the end of the text, select one or more characters until you find the first dash or underscore
(?<=KEY2=).*?(?=;)KEY1=A;KEY2=B;KEY3=C;BThis reads: from the first occurrence of ‘KEY2=’ select all characters until you find the next semicolon.
^(?>(.+?)(?:,|$)){4}A ,B,C,D,E,FDSubstitute {4} with another number to select another item from the list. For example {3} would select C.If your list does not use comma as the separator. substitute the comma in the regular expression with your list separator. For example if your list is ‘A:B:C:D:E:F’ you should use ^(?>(.+?)(?::|$)){4}
^(?>(.+?)(?: , | ,|, |,|$)){4}A ,B, C , D,E, FDUse this variant if the items in your list are, in addition to the separator, separated by spaces on either side of the separator.