• Post Reply Bookmark Topic Watch Topic
  • New Topic

Extracting a code fragment using reg ex  RSS feed

 
Ashwin Pai
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

Here is what I am trying to do...
Consider the following SQLWindows code


My requirement is, I need to extract the Function block if the function has a particular keyword. ie If I look for FALSE, I need my reg ex to match the function that has this key word. ie it would return


I need some directions as to how I could approach this.

Thanks in advance
Ashwin
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not a regex expert but i really am not sure whether you should do it using regex.
What you are talking about a lexical parser that understands a particular language, in your case a SQL code.
I would recommend going for something like antlr that will logically parse your code and let you do complex compiler like activities.
Of course, this is just my opinion and based on your requirements, it may or may not be applicable.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are probably correct Nitesh: a programming language is in a context-free grammar and a regex parses a regular grammar, so regexes probably can't parse program code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!