Results 1 to 3 of 3
- 06-10-2011, 05:38 AM #1Member
- Join Date
- Aug 2008
- Rep Power
How to string.indexOf for multiple strings and return first instance?
Basically, I am searching a string containing html. And I want to find the first instance of "<input" or "<div" or "<form", and return the index of whichever comes first?
I have a way to do it with many loops, but it's really inefficient. Is there a simple way to do it? maybe with regex?
- 06-10-2011, 05:49 AM #2
If all the html is in a single String then simply do index of input, div and form. Then find the min of those three values and return it.
- 06-10-2011, 07:15 AM #3Is there a simple way to do it? maybe with regex?
Matcher has a method start() which returns "the start index of the previous match."
Some learning resources for regex:
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)
You may get better help if you describe the requirement: why you need to know the first index of "<input" or "<div" or "<form"
- By sjunejo in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 06-09-2011, 12:17 PM
- By albertkao in forum New To JavaReplies: 1Last Post: 11-04-2010, 06:53 PM
- By ras_pari in forum Advanced JavaReplies: 3Last Post: 10-07-2009, 07:33 AM
- By Manfizy in forum New To JavaReplies: 17Last Post: 05-25-2009, 12:07 PM
- By trojansc82 in forum New To JavaReplies: 0Last Post: 11-15-2008, 10:09 PM