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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression 1

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,963
0
36
US
I simply want a regular expression to find any instance of an @ symbol anywhere in a string.

I used /@/ but it does not seem to work. Any ideas?

Thanks.

Swi
 
Thanks, is there any way to look for two @ signs or is it just @@

Swi
 
strongm,

Hate to be a both but what would a way to have an expression that says if a string excludes the @ symbol?

Thanks.

Swi
 
Excluding? RegEx isn't that good at finding non-matches ... but the following (credit not mine) should do the trick: ^((?!@).)*$
 
You are the man!!!

Thanks.

Swi
 
What about instr?
strTestCharacter="@" (or "@@" if looking for 2)
if Instr(strExpression,strTestCharacter) > 0 then
' Found
else
' Not Found
end if

If there are multiple instances of the strTextCharacter then you use a do - loop
Counter=1
Do until Counter= 0
Counter=Instr(Counter,strExpression,strTestCharacter)
CounterString=CounterString & str(counter) &"'"
Loop

ounterstring will look like "10, 22, 56" if indicating 3 occurrences
 
Sure, in a simple scenario instr is probably a preferable solution (simpler, faster, lightweight, builtin).

However Regular Expressions are a very powerful tool that allow us to do a LOT more than simply finding the position of a character. Given Swi's very specific request for a regexp solution I suspect that simply looking for @ is not the ultimate goal, even if that goal is as simple as learning about regexps (as I rather suspect that they are familiar with Instr and would already be using it if it were appropriate)

 
Is regexp any faster or slower than using instr.
I'm talking about say finding every occurrence of a 3 digit number (Eg. 385) in a 10k text string (CSV version of an Excel spreadsheet).
Alternatively how would this compare timewise with updating a database table from the data and using a SQL query?
 
The only reason I want to use a regular expression in this case is because I am locked down in an application that I can only enter a regular expression into.

Does anyone know if there is a way to have a regular expression evaluate only if there is text to evaluate?

Meaning, the application I am using this in is causing an error because no text has been entered.

So in other words, in the regular expression can I conditionally evaluate based on whether or text has been entered?

I have the following regular expression for a phone#.

^\({1}[2-9]\d{2}\){1}\s?\d{3}\-\d{4}

I would like to add something to where an empty string is acceptable as input.

Thanks.

Swi
 
Looks like I got it worked out. Thanks anyway.

^$|^\({1}[2-9]\d{2}\){1}\s?\d{3}\-\d{4}

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top