Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Let's say I have a string which has relational operators:

"x<y , x=y , x<=y , x>y , x>=y" 

How can I split this?

If I use [<>=] it'll split x<=y as (x and =y).

Is there any simple way to do it without writing our own function to split?

share|improve this question
use [<>=]+ (not the +) to match multiple chars – ratchet freak Apr 30 at 12:57
why is it migrated? – Dineshkumar Apr 30 at 13:58

migrated from programmers.stackexchange.com Apr 30 at 13:03

2 Answers

up vote 6 down vote accepted

If you want to split using any sequence of characters (and not only any character), then you should use:

[<>=]+

The + here means 1 or more

share|improve this answer
what + here means? (we would give "<+" for 1..* < but this one?) – Dineshkumar Apr 30 at 13:55
@Dineshkumar, you should be aware that the above pattern will also match things like <<, >>, =<, =>, and ==. – MetaFight Apr 30 at 17:04
1  
More precisely, [<>]=?|= – kevin cline Apr 30 at 18:29

You could have a Recursive Descent Parser. Is easy to implement and easy to mantain. You might want to look this.

share|improve this answer
True but this is a scanning problem, not a parsing problem (yet). Not an answer. – EJP Apr 30 at 23:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.