Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressions question 1

Status
Not open for further replies.

ktucci

Programmer
Apr 23, 2001
146
US
how do i use regular expressions to look for '\w{2,5}' but not have the result be a number by itself

i would want to match:(letter number combinations)

abc1a
1abcd
abcde
1234a
a4bcd

but not:(any integer without a letter)

12345
123
12
22222

any help will be greatly appreciated

thanks

keith
 
Have you tried the Instr() function? It checks for the existence of your supplied string within another string. Or maybe I'm not clear on what you are wanting to do.

Lightseeker
 
i have regular expression below and just need to modify the \w{2,5} portion to not allow matches of characters containg only integers

re.Pattern = "(\s{1}\d{1,3}\s{2\w{2,5}(\s{2}[/].*?|\s{1}.*?))(?=(\s{1}\d{1,3}\s{2}\w{2,5}\s{1}|---SUMY))"

Set Matches = re.Execute(strText)
i = 0
For Each Match In Matches
u = u + 1
Set Match = Matches(i)
i = i + 1

re.Pattern = "\s{1}(\d{1,3})\s{2}([A-Z0-9]{2,5})(.*)"
 
whooo. Are you trying to search and replace, weed out what you don't want? Is this a class that is handling encryption? Help us understand.

lightseeker
 
imagine i would like to parse this line text and my below expression does that fine but the 'PVLFL' may be combination of alpha numeric character which is OK but on occasion a integer may show up with no alpha characters in and i would like to NOT match those occurences

1 PVLFL /CLS 67,PLNA,135400,,NE I 01-18-99

at the simplest form '\w{2,5}' does the match but will also include:

12345
1234
123


which i do not want to include

so far i have tried [^100-99999] with no luck, i just cant seem to get this one

thanks

keith

 
I think LightSeeker is on the correct path.
If you wish to examine the expression, you should make
as string variable, the use "InStr()" to examine it. Then
use Mid() to copy the portion of the string before and after
the search object, etc.
 
the file that contains this pattern may have the pattern occur 1000's of times in no particular order thus i am using regular expressions to pattern match...there is no way i could do anything before i pattern match...i believe the answer i need resides in regular expressions and may require me to use a '|' or a '~' the exclude that pattern...i am just not sure how to implement either of those to give me the results i need

thanks

keith

 
I believe that regular expression search is only supported in VBScript, not in VB5 or VB6.

Suggest you re-post in VBScript Forum
 
no, i am using it in VB6...it is not regular expression search...what i am doing looks something like this

re.Pattern = "(\s{1}\d{1,3}\s{2}[A-Z0-9]{2,5}(\s{2}[/].*?|\s{1}.*?))(?=(\s{1}\d{1,3}\s{2}[A-Z0-9]{2,5}\s{1}|---SUMY))"

Set Matches = re.Execute(strText)
i = 0
For Each Match In Matches
u = u + 1
Set Match = Matches(i)
i = i + 1

re.Pattern = "\s{1}(\d{1,3})\s{2}([A-Z0-9]{2,5})(.*)"

Set Matches1 = re.Execute(Match.SubMatches(0))
j = 0
For Each Match1 In Matches1
Set Match1 = Matches1(j)
j = j + 1
 
anyone have any ideas on this...

thanks

keith
 
Um, yes - but I'm still thinking about it before being prepared to commit electronic pen to electronic paper...
 
thanks

i just ried this but still no luck...

\w{3,5}[^100-9999}]
 
what about isNumeric()? for any item that is numeric? do this before the rest of the regexp to weed out the all numeric data...

hth

Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
i wish it was that easy...i only want NOT match the pattern when that occurs in that particulat part of the pattern...the pattern is much larger then just that one piece plus it uses a look ahead to match the next occurence of the pattern without capturing the data...

thanks

keith
 
hi keith.

this was a nice one to get the old grey matter working !

\w matches [A-Za-z0-9_] so you can't use this for the second 'word' in your data string because it could contain numbers.

anyway, i have taken your data string and butchered it slightly for this test (this is what i am guessing your data to look like):

1 PVLFL /CLS 67,PLNA,135400,,NE I 01-18-99
1 PV7FL /CLS 67,PLNA,135400,,NE I 01-18-99
1 123 /CLS 67,PLNA,135400,,NE I 01-18-99

i believe you want to match the top two lines but NOT the last.

my answer will probally make your regexp twice as long so im sorry, the only problem with complex regexp is that they are quite unreadable.

this will match a word with any combination of numbers and letters except all numbers:

([A-Za-z]+|[A-Za-z]+[0-9]+[A-Za-z]+|[0-9]+[A-Za-z]+[0-9]+|[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+)

the brackets in this case are for the OR'ed expression i'm not sure if the regexp library your using needs this.

to explain each OR'ed subexpression matches a combination of letters and characters to form an alphanumeric or alphabetic word but NOT just a numeric word.

obviously you will have to incorporate this expression into your own, please dont ask me to help you with that !!

hope this helps.

Richard.

 
thanks...

one question..is there a way to limit the match to between 3 and 5 characters

thanks again for your help

keith
 
This could get real complicated, real quick. I suggest a shortcut to avoid making the regexp overly obtuse.

Try the following before your main re.execute, which essentially deletes the unwanted lines:

re.Pattern = "(^\s{1}\d{1,3}\s{2}\d{2,5}.*\r\n)"
strText= re.Replace(strText, "")
 
yes, unfortunately this makes the expression even more ugly !

+ actually translates to {1,}
* actually translates to {0,}

given the above all you need to do is for each + in the expr change it to {3,5}

Rich.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top