Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

Description

This code can be adapted to match any character or word in a list using a textbox as follows:

"^[" & TextBox2.Text & "]\w+"

However, for this to work the text in the main textbox needs to be made into a list replacing whitespaces, tabs, carriage returns, etc. with a carriage return. The list doesn't have to be sorted to work. I just tried this and can now extract from a text a list of words beginning with 'a' and insert them into a listbox. This is great for getting lists of words beginning with a particular letter or even a particular prefix!

However, I don't understand why my regex expression doesn't include the indefinite article 'a' in the list? Don't know if anyone has any ideas? Also, I need to modify my code a little using ToLower for the the list because Capitalized words aren't being included in the list!

Hope this helps you as much as it has me!

Submitted by anonymous - a year ago