Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 28th, 2008, 05:56 PM
Samuel Adams Samuel Adams is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Location: Boston, MA
Posts: 5 Samuel Adams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 48 m 21 sec
Reputation Power: 0
Extract String Within Parenthesis

I have the following string of characters in the body of an email:

(name)This is a line.

I want to extract the "name" from the parens. What is the easiest way to go about this? The characters in parens are always going to be alpha, no numbers.

Reply With Quote
  #2  
Old October 29th, 2008, 03:02 AM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,714 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 6 m 6 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
The "easiest way to go about" it depends on the language.

You're posting in the regex forum so I can only assume you're looking for a regex answer.
Code:
/\([a-z]+\)/

Reply With Quote
  #3  
Old October 29th, 2008, 10:48 AM
Samuel Adams Samuel Adams is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Location: Boston, MA
Posts: 5 Samuel Adams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 48 m 21 sec
Reputation Power: 0
I'm using VBScript and it didn't seem to like the above regex very much. Below is a code snippet that is taking what is in parenthesis:

Code:
Set objRegEx = CreateObject("VBScript.RegExp")
Set objRegEx2 = CreateObject("VBScript.RegExp")
strTest="(Word)This is a test"

objRegEx.Pattern = "([A-Z][a-z]*)"
Set colMatches = objRegEx.Execute(strTest)
If colMatches.Count > 0 Then
        For Each strMatch In colMatches
            MsgBox strMatch
        Next
End If


My problem now? I want to take everything AFTER the word in parens (so "This is a test"). I tried:
Code:
objRegEx.Pattern = "[^([A-Z][a-z]*)]"
Set colMatches = objRegEx.Execute(strTest)
If colMatches.Count > 0 Then
        For Each strMatch In colMatches
            MsgBox strMatch
        Next
End If

To no avail... any advice?

Reply With Quote
  #4  
Old October 29th, 2008, 11:21 AM
jesh jesh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 2 jesh User rank is Lance Corporal (50 - 100 Reputation Level)jesh User rank is Lance Corporal (50 - 100 Reputation Level)jesh User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 h 28 m 31 sec
Reputation Power: 0
I don't know VBScript too well these days so forgive me any errors that I might include in regards to that, but I think the following might help:

Code:
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.IgnoreCase = True
objRegEx.Pattern = "\(([a-z]+?)\)(.+)"

strTest="(Word)This is a test"

Set colMatches = objRegEx.Execute(strTest)

If colMatches.Count == 2 Then
    wordInParens = colMatches(0)
    wordOutsideParens = colMatches(1)
End If

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Extract String Within Parenthesis

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap