#1
|
|||
|
|||
Regex string separation help. (or splitting strings in to pieces)
Hi friends,
Suppose this is my packagename string. text1-text2 I use (.*)-(.*) as regex rule to split this string. Result: <jd:orgpackagename:1> = text1 <jd:orgpackagename:2> = text2 That's good. But if my packagename has two of "-" character like text1-text2-text3 then result is: <jd:orgpackagename:1> = text1-text2 <jd:orgpackagename:2> = text3 if my expectation is using first "-" character as separation point, how regex rule should I use? In other words, for second case my expectation is this: <jd:orgpackagename:1> = text1 <jd:orgpackagename:2> = text2-text3 A sample link to test: **External links are only visible to Support Staff****External links are only visible to Support Staff** With current rule, for the test link I get this: <jd:orgpackagename:1> = Moero Knight-Monkey <jd:orgpackagename:2> = Happy New Year But my expectation is this: <jd:orgpackagename:1> = Moero Knight <jd:orgpackagename:2> = Monkey-Happy New Year How should I modify my regex rule? |
#2
|
||||
|
||||
Try this: (.*?)-(.*)
__________________
FAQ: How to upload a Log |
#3
|
|||
|
|||
Yes!
:thumbup:
Yes, this is what I'm looking for. Thanks a lot. By the way as you may guess, I'm a real and %100 newbie in regex. Could you please advice me some document or web page as reference (with many examples, if possible)? I've seen so many programs using regex but I'm completely out because of my ignorance. |
#4
|
||||
|
||||
I suggest to google for regex and wikipedia is a good start
__________________
JD-Dev & Server-Admin |
Thread Tools | |
Display Modes | |
|
|