XML regular expression
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 3
- Joined: Thu Jun 07, 2012 4:27 pm
XML regular expression
One of the tool we use reads a XML file to generate the number of lines of code from given source files types (like.. java,sql etc..). Below is the line of code wirtten in the XML file which is used to ignore the lines which have only the words "do" or "while".
<codeArea name="Begin/End tags" isCode="false" >
<expression>^\s*begin\s*$</expression>
<expression>^\s*end\s*$</expression>
</codeArea>
In the same way, how can I write the code to ignore the "case" statements which is used with "switch" in programming languages. For example, in the below code i want to ignore "case" statements
switch ((char)(e.KeyChar))
{
case '\b':
case "Thr":
case '1':
}
I tried below way, but it doesn't worked. could someone please help on it.
<expression>^\s*case[*]:\s*$</expression>[/b]
<codeArea name="Begin/End tags" isCode="false" >
<expression>^\s*begin\s*$</expression>
<expression>^\s*end\s*$</expression>
</codeArea>
In the same way, how can I write the code to ignore the "case" statements which is used with "switch" in programming languages. For example, in the below code i want to ignore "case" statements
switch ((char)(e.KeyChar))
{
case '\b':
case "Thr":
case '1':
}
I tried below way, but it doesn't worked. could someone please help on it.
<expression>^\s*case[*]:\s*$</expression>[/b]
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XML regular expression
Hi,
I'm not sure what type of regular expressions are you using. From seeing ^ and $, I'm guessing they are Perl/Java like.
The regular expression would look like this:
If ".*?" is not accepted, use ".*".
Regards,
Adrian
I'm not sure what type of regular expressions are you using. From seeing ^ and $, I'm guessing they are Perl/Java like.
The regular expression would look like this:
Code: Select all
^\s*case\s+.*?:\s*$
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 3
- Joined: Thu Jun 07, 2012 4:27 pm
Re: XML regular expression
^\s*case\s+.*?:\s*$
The above expression you given worked pretty well. Is it perl syntax? Could you plese help me in below two cases.
CASE1:- If any line starts with : (colon), then that line should be ingored. For example, in the below line the word END stars with : , so this line should be ignored. (there is no space betwwen : and END word)
:END
CASE 2:- if any line starts with the word struct then that line should be ignroed. for example, below line should be ingnored.
struct simple
The above expression you given worked pretty well. Is it perl syntax? Could you plese help me in below two cases.
CASE1:- If any line starts with : (colon), then that line should be ingored. For example, in the below line the word END stars with : , so this line should be ignored. (there is no space betwwen : and END word)
:END
CASE 2:- if any line starts with the word struct then that line should be ignroed. for example, below line should be ingnored.
struct simple
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XML regular expression
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 3
- Joined: Thu Jun 07, 2012 4:27 pm
Re: XML regular expression
<expression>^\s*}\s+else\s+{.*$</expression>
i have written above regular expression to ignore lines which are in below format and It is working as expected
} else {
But, if add anything after "else" word, it is still ignoring the line. for example, it should not ignore below line.
} else if (2>3) {
could you please correct it
} else { ------ This line should be ignored
} else if (2>3) { ------ This line should not be ignored
i have written above regular expression to ignore lines which are in below format and It is working as expected
} else {
But, if add anything after "else" word, it is still ignoring the line. for example, it should not ignore below line.
} else if (2>3) {
could you please correct it
} else { ------ This line should be ignored
} else if (2>3) { ------ This line should not be ignored
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XML regular expression
You're not using the wildcard in the right place. You should use it before the left curly bracket({), because that's where you have the "if".
<expression>^\s*}\s+else\s+.*?{$</expression>
Note that for most languages the spaces are optional near curly brackets. So you may want to use \s* instead of \s+.
Also note that for some (if not most) regular expression engines the curly, square and round brackets are special characters and they should be escaped when used as literals in an expression.
e.g. \{
Regards,
Adrian
<expression>^\s*}\s+else\s+.*?{$</expression>
Note that for most languages the spaces are optional near curly brackets. So you may want to use \s* instead of \s+.
Also note that for some (if not most) regular expression engines the curly, square and round brackets are special characters and they should be escaped when used as literals in an expression.
e.g. \{
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service