473,511 Members | 16,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with a Regular Expression

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
3 1817

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3682
by: Steve | last post by:
Hello, I am writing a script that calls a URL and reads the resulting HTML into a function that strips out everthing and returns ONLY the links, this is so that I can build a link index of various...
5
2490
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
4
3206
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
6
489
by: JohnSouth | last post by:
Hi I've been using a Regular expression to test for valid email addresses. It looks like: \w+(\w+)*@\w+(\w+)*\.\w+(\w+)* I've now had 2 occassions where it has rejected and email address...
3
2276
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
1
3694
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
3
2552
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
6
2216
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
14
2245
by: Chris | last post by:
I need a pattern that matches a string that has the same number of '(' as ')': findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = Can anybody help me out? Thanks for any help!
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.