473,320 Members | 1,920 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,320 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 1042
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:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
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...
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...

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.