INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Regular Expression

Regular Expression

(OP)
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

RE: Regular Expression

Just @ should work

RE: Regular Expression

(OP)
Thanks, is there any way to look for two @ signs or is it just @@

Swi

RE: Regular Expression

@@ should work. Or @{2}. Or @{2,2}

RE: Regular Expression

(OP)
Ok, thanks.

Swi

RE: Regular Expression

(OP)
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

RE: Regular Expression

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

RE: Regular Expression

(OP)
You are the man!!!

Thanks.

Swi

RE: Regular Expression

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

RE: Regular Expression

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)

RE: Regular Expression

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?

RE: Regular Expression

(OP)
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

RE: Regular Expression

(OP)
Looks like I got it worked out. Thanks anyway.

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

Swi

RE: Regular Expression

You only gave us 9 minutes ... winky smile

RE: Regular Expression

(OP)
glasses

Swi

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close