Non-capturing/non-matching regular expressions (regex)?
-
I'm trying to use a regex expression to get details from within XML tags without matching the tags themselves. For example: <tag>Hello there</tag> would return: "Hello there" I've tried using the ?: operator like so: (?:<tag>).*(?:</tag>) which doesn't work. Perhaps I've misunderstood ?:'s function. Either way, I'd like to see a regex expression to achieve my desired result. Thanks for your time, Derek
-
Answer:
You can fix your statement above by simply removing the greedy operators (?:) all together. However, I think you will find that regular expressions are not very good at doing what you are trying to do. They don't match nested bracket pairs (or in your case, pairs of tags) in the correct way whether you use the greedy operator or not. For example, if you have something like this: <tag><tag><tag>Hello there</tag></tag></tag> You won't be able to match the start/end tags. If you are doing this in perl, there are plenty of xml parsers out there you can use. Writing your own is hard and won't work the way you are trying to do it.
Derek at Yahoo! Answers Visit the source
Related Q & A:
- Does anyone knows how TeamViewer gets screen capturing?Best solution by Super User
- What's the use of Deterministic Regular Expressions?Best solution by Stack Overflow
- how to regex remove this?Best solution by Stack Overflow
- How to input variable inside regex javascript?Best solution by stackoverflow.com
- Are Tourism Industry geared up for matching skill and educated car/bus driver?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.