I'm having trouble constructing a pattern that will allow me to find all the words in a string that have at least one number anywhere in them so I can replace them with a blank which effectively deletes the word from the string. For example, the pattern should find each of the following words: 1ABC, 99ABC, ABC1, ABC99, ABC1D, and ABC99D. Is this possible or will I need to use three separate patterns and make three separate calls to the replace function?
Thanks in advance for any help.
that is a word (between two word boundaries) consisting of any number of letters and digits with at least on digit.
It will also match simple numbers, though. I'm don't know it that is acceptable. Otherwise this might do
/\b(\w*(\d\w¦\w\d)\w*)\b/
The minimum match here is 1A or A1.
I only match one \d because that was what you asked. The \w will also match digits if necessary.
If you only want uppercase letters and digits, substitute [A-Z0-9] for \w.
René.
/\b([A-Z\d]*(?:[A-Z]\d¦\d[A-Z])[A-Z\d]*)\b/ The regex above will only match one or more letters with one or more numbers. It uses a non-capturing match so that only the whole word is captured for efficieny. In perl it's more efficient to only capture what is used rather than the capture the whole word and parts of the word. Although I am not sure if this is compatible with VB's regex engine.
The dot star (.*) will match nearly anything, not just letters. The regex you've chosen will match something like "A#4", the entire string "R3S E2D", or even just the number "9".
I need a pattern that will search on 2+ search terms in a single string. For example, if my search terms are, "dog cat song," I want it to match the following lines:
catdog song
song-cat.dog
SONG.DOG.cat
...
My current solution involves a recursive function, but the search area is quite big and the process just slows to a crawl. A single pattern would definitely be preferrable.
Oh yeah, as with GaryK, I am also using VBScript Regular Expressions.
------------------
Ah, I should also specify that I don't want the Regex to match things like:
songsongsong
catcatdog
...
All string it matches must have the search terms specified.
See if this works:
/(.*(cat¦dog¦song).*(cat¦dog¦song).*(cat¦dog¦song).*)/
The vertical pipe represent OR, the .* means "zero or more of any character except a newline". The parenthesis not only enclose the OR statements but also group the results, which is why the whole statement is enclosed in parenthesis so $1 or \1 returns the whole string.
RegEx Coach [weitz.de]