472,791 Members | 1,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Help w/ regex for parsing parameters

I have to process parameter input strings of key/value pairs /key=value where
value _may_ contain a slash /.

Here is a sample input string:

/def=gamma chain (FT2) /name=NULL /p_id=CF11423:SF7 /fn=Defense/receptor member
/process=Signal transduction /len=98
Here is the regex:

\s*(?<val>.*?)\s*=
Here is the output:

0: ""
1: "def"
2: "gamma chain (FT2) "
3: "name"
4: "NULL "
5: "p_id"
6: "CF11423:SF7 "
7: "fn"
8: "Defense"
9: "receptor member /process"
10: "Signal transduction "
11: "len"
12: "98"

Everything is fine *except* for the /fn value, I don't want it to split between
defense and receptor. Is this possible w/ a regex, or should I just code my
own split routine to handle this case?
Nov 16 '05 #1
2 2148
I'm no regex guru, but you can try this one- works for your test string, and
gives key/value pairs as named groups.

/(?<key>[^=]*)=(?<value>.*?)(?=\s/|$)

"Julie" <ju***@nospam.com> wrote in message
news:41***************@nospam.com...
I have to process parameter input strings of key/value pairs /key=value
where
value _may_ contain a slash /.

Here is a sample input string:

/def=gamma chain (FT2) /name=NULL /p_id=CF11423:SF7 /fn=Defense/receptor
member
/process=Signal transduction /len=98
Here is the regex:

\s*(?<val>.*?)\s*=
Here is the output:

0: ""
1: "def"
2: "gamma chain (FT2) "
3: "name"
4: "NULL "
5: "p_id"
6: "CF11423:SF7 "
7: "fn"
8: "Defense"
9: "receptor member /process"
10: "Signal transduction "
11: "len"
12: "98"

Everything is fine *except* for the /fn value, I don't want it to split
between
defense and receptor. Is this possible w/ a regex, or should I just code
my
own split routine to handle this case?

Nov 16 '05 #2
Philip Rieck wrote:

I'm no regex guru, but you can try this one- works for your test string, and
gives key/value pairs as named groups.

/(?<key>[^=]*)=(?<value>.*?)(?=\s/|$)


Nice -- works like a charm! Thanks!
Nov 16 '05 #3

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

Similar topics

4
by: Chuck Haeberle | last post by:
I have an interesting regular expression challenge for someone more experienced with them than I for a data layer class... I need an expression to search a SQL statement (any type, SELECT INSERT...
1
by: Julie | last post by:
Suppose a string of the following format: /field=value string /field2=value string2 /field3=value string3 where field is , , and _ value string is any alphanumeric text that doesn't...
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....
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
4
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: ...
9
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
3
by: aspineux | last post by:
My goal is to write a parser for these imaginary string from the SMTP protocol, regarding RFC 821 and 1869. I'm a little flexible with the BNF from these RFC :-) Any comment ? tests= def...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.