This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Regular Expressions  RSS feed

 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am messing around on my own with regular expressions and I don't know how to do something. I want to parse text for something like this:

%functionName("asbdaf()", "aadfa")

I want everything starting with the percent sign and ending with the last closing paranthesis (the first closing paranthesis doesn't count because it is within quotes).

I also want to know how to find stuff like this:

${something something anything \} anything else}

and here I want everything from the dollar sign to the last closing brace (first one doesn't count because it is "escaped" with the \ character.

Any ideas?
 
Casey Buresh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not exactly sure what your doing, but part of what could be wrong is that % is modulus and if you don't know what modulus is lookhere.
 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry my description may not be clear. i am parsing text that may look like this


and I am looking for a regular expression that would return
 
Casey Buresh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see why it wouldn't work, I'm really just a dabbler in parsing and
that kind of stuff. What are you trying to parse it to parse and string to and int like if you had: anything like that, only with String and not just numbers? jw. sry if i'm no help\...
 
Michael Labuschagne
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Don't think you'll achieve what you're trying to do with regular expressions.

I would use for loops which go through the text using counters (depending on the "control characters")

If you could send an entire sample of the text you're trying to pass but in the mean time for the e.g. text you had:



Your result String variable should contain the desired string

Just check my substring method not sure if my arguments there are 100 %

Hope this helps

By th way: this won't work if the string has multiple occurrences of your desired string thats why you should send an example of an entire file you're passing

but in any case you should be able to expand on this to get it to work for what you want
 
Ricky Clarkson
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regular expressions are the wrong level for lexing. Use a lexer. One probably already exists for whatever language that code is in.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!