By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Help with a Regular Expression

P: n/a
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression
Help

--------------------------------------------------------------------------------

I need help writing a regular expression that only returns part of a
string.

For Example I have a multi-line text fragment like below:

PC ADVISORS, LC
1234 MT. PARMA ROAD. SUITE A1
ATLANTA, GA 30097
PH. (404) 555-1212

I write a regular express that retrieves the second line. I want to
only return all the data before SUITE A1 in the line. The regular
expression I have so far is "\n\n.*?! S" . This returns "1234 MT.
PARMA ROAD. S" . Could anybody help me figure out how to write a
regular expression that only returns "1234 MT. PARMA ROAD." . The
stipulation is that the first part of the line is a variable length.

Thanks,

John

Jul 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Mr.Steskal" <js******@recidev.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression
Help

--------------------------------------------------------------------------------

I need help writing a regular expression that only returns part of a
string.

For Example I have a multi-line text fragment like below:

PC ADVISORS, LC
1234 MT. PARMA ROAD. SUITE A1
ATLANTA, GA 30097
PH. (404) 555-1212

I write a regular express that retrieves the second line. I want to
only return all the data before SUITE A1 in the line. The regular
expression I have so far is "\n\n.*?! S" . This returns "1234 MT.
PARMA ROAD. S" . Could anybody help me figure out how to write a
regular expression that only returns "1234 MT. PARMA ROAD." . The
stipulation is that the first part of the line is a variable length.
Will it always end in "SUITE xyz?" If so, use something like "(\n\n.*?!)
SUITE" and reference the sub-match.
Jul 11 '07 #2

P: n/a
Mr.Steskal wrote on 11 jul 2007 in comp.lang.javascript:
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression
Help

-----------------------------------------------------------------------
---------

I need help writing a regular expression that only returns part of a
string.

For Example I have a multi-line text fragment like below:

PC ADVISORS, LC
1234 MT. PARMA ROAD. SUITE A1
ATLANTA, GA 30097
PH. (404) 555-1212

I write a regular express that retrieves the second line. I want to
only return all the data before SUITE A1 in the line. The regular
expression I have so far is "\n\n.*?! S" . This returns "1234 MT.
PARMA ROAD. S" . Could anybody help me figure out how to write a
regular expression that only returns "1234 MT. PARMA ROAD." . The
stipulation is that the first part of the line is a variable length.
<script type='text/javascript'>

var t = 'PC ADVISORS, LC\n1234 MT. PARMA ROAD. SUITE A1\n'+
'ATLANTA, GA 30097\nPH. (404) 555-1212'

t = t.replace(/(^.*?\n)|( suite[\s\S]*)/ig,'')

alert(t)

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 11 '07 #3

P: n/a
In comp.lang.javascript message <11*********************@w3g2000hsg.goog
legroups.com>, Wed, 11 Jul 2007 08:52:51, Mr.Steskal
<js******@recidev.composted:
>For Example I have a multi-line text fragment like below:

PC ADVISORS, LC
1234 MT. PARMA ROAD. SUITE A1
ATLANTA, GA 30097
PH. (404) 555-1212
The first question must be whether SUITE... will always be present.
Then, if it is not, what should the result be.

In practice, it will make little difference; but, for readability, it
might be better to use .match when the underlying intention is to copy a
fragment and .replace when it is to edit the contents.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Delphi 3? Turnpike 6.05
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htmclpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.htmlnews:borland.* Guidelines
Jul 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.