473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Regex help needed

I need to split a string at every 2nd occurrence of a delimiter.

The string is:
CLAS|DIST|WKPL|ONLN|FLEX|FLXO|MIXD|OTHR|

and I need the output to be:
CLAS|DIST|<br>
WKPL|ONLN|<br>
FLEX|FLXO|<br>
MIXD|OTHR|

Does anyone know the right regex expression to use?

Many thanks
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #1
2 1043
Jeff North wrote:
I need to split a string at every 2nd occurrence of a delimiter.

The string is:
CLAS|DIST|WKPL|ONLN|FLEX|FLXO|MIXD|OTHR|

and I need the output to be:
CLAS|DIST|<br>
WKPL|ONLN|<br>
FLEX|FLXO|<br>
MIXD|OTHR|

Does anyone know the right regex expression to use?

var x = 'CLAS|DIST|WKPL|ONLN|FLEX|FLXO|MIXD|OTHR|';

alert( x.match( /\w{4}\|(\w{4})?/g ).join('|<br>') + '|' );

The trailing '|' causes a problem, both in the input string and for the
output chunks. It would be better (easier?) if your output was:

CLAS|DIST<br>
WKPL|ONLN<br>
FLEX|FLXO<br>
MIXD|OTHR


--
Rob
Jul 23 '05 #2
On Mon, 11 Jul 2005 04:42:13 GMT, in comp.lang.javascript RobG
<rg***@iinet.net.auau> wrote:
| Jeff North wrote:
| > I need to split a string at every 2nd occurrence of a delimiter.
| >
| > The string is:
| > CLAS|DIST|WKPL|ONLN|FLEX|FLXO|MIXD|OTHR|
| >
| > and I need the output to be:
| > CLAS|DIST|<br>
| > WKPL|ONLN|<br>
| > FLEX|FLXO|<br>
| > MIXD|OTHR|
| >
| > Does anyone know the right regex expression to use?
|
|
| var x = 'CLAS|DIST|WKPL|ONLN|FLEX|FLXO|MIXD|OTHR|';
|
| alert( x.match( /\w{4}\|(\w{4})?/g ).join('|<br>') + '|' );
|
| The trailing '|' causes a problem, both in the input string and for the
| output chunks. It would be better (easier?) if your output was:
|
| CLAS|DIST<br>
| WKPL|ONLN<br>
| FLEX|FLXO<br>
| MIXD|OTHR


Thanks for that. Works perfectly.
One of these days I'll get to learn regex :-)
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning...
4
by: H | last post by:
This is kind of an followup on oneof my previous questions, and it has with RegEx to do. I have a string containing of several words. What would a good regex expression looklike to get one match...
2
by: D | last post by:
My first attempt at this and I'm searching formulas like so RIGHT(TEXT(A15,'yy'),1)*1000+A15-CONCATENATE(1,'-','jan','-',TEXT(A15,'yy'))+1 I want to extract the row / col coordinates (A15 in...
17
by: steve | last post by:
here's the deal...cvs, tick encapsulted data. trying to use regex's to validate records. here's an example row: 'AD,'BF','132465','06/09/2004','','BNSF','A','TYPE','1278','','BR','2999',''...
4
by: Ya Ya | last post by:
Hi, I have a string with some fixed text and variable text. For example: "this is a fixed text THE NEEDED INFO more more fixed text". How do I get the the variable text (THE NEEDED INFO) from this...
5
by: lgbjr | last post by:
Hello All, I have the following type of string: "X:Y\Z.exe" "123" What I need is an array of strings with the information from within each set of quotes. I was trying to use a Regex.Split, but...
13
by: Chris Lieb | last post by:
I am trying to write a regex that will parse BBcode into HTML using JavaScript. Everything was going smoothly using the string class replace() operator with regex's until I got to the list tag....
4
by: ad | last post by:
I am useing VS2005 to develop wep application. I use a RegularExpress both in RegularExpressionValidator and Regex class to validate a value. The RegularExpress is 20|\-9|\-1|?\d{1} When I...
3
by: | last post by:
I'm analyzing large strings and finding matches using the Regex class. I want to find the context those matches are found in and to display excerpts of that context, just as a search engine might....
4
by: Flomo Togba Kwele | last post by:
I am having difficulty writing a Regex constructor. A line has a quote(") at its beginning and its end. I need to strip both characters off. If the line looks like "1", I need the result to be 1....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.