RegularExpressions

  • Thread starter Thread starter Bill Yin
  • Start date Start date
Unless you need resiliency in the pattern, you are better of using IndexOf.
By resiliency, I mean the ability to handle tags that aren't formed as well
as you demonstrate below.
 
Which faster using indexOf or RegularExpressions?


Justin Rogers said:
Unless you need resiliency in the pattern, you are better of using IndexOf.
By resiliency, I mean the ability to handle tags that aren't formed as well
as you demonstrate below.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


Bill Yin said:
I want get the Matchs
<li>[xxxxxxxxxxxxxxxxxxxxxxxxx</li>
begin:<li>[
end:</li>
 
IndexOf is going to be massively faster in most cases in searching for
start and end tags of fixed form like you show below. Actually I take
that back, you are actually going to need to use something that does
a substring match:

http://weblogs.asp.net/justin_rogers/archive/2004/03/14/89545.aspx

The above algorithm should get you going.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


Bill Yin said:
Which faster using indexOf or RegularExpressions?


Justin Rogers said:
Unless you need resiliency in the pattern, you are better of using IndexOf.
By resiliency, I mean the ability to handle tags that aren't formed as well
as you demonstrate below.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


Bill Yin said:
I want get the Matchs
<li>[xxxxxxxxxxxxxxxxxxxxxxxxx</li>
begin:<li>[
end:</li>
 
IndexOf should be, given that Regexes have the tradeoff of more advanced functionality. Try profiling it - I tried compuware devpartner community edition profiler - free, integrates into VS.NET and I must say the support is quite good aswell. Not to mention works dead well and highlights the slowest line of code in red - something I find dead useful!


Bill Yin said:
Which faster using indexOf or RegularExpressions?


Justin Rogers said:
Unless you need resiliency in the pattern, you are better of using IndexOf.
By resiliency, I mean the ability to handle tags that aren't formed as well
as you demonstrate below.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


Bill Yin said:
I want get the Matchs
<li>[xxxxxxxxxxxxxxxxxxxxxxxxx</li>
begin:<li>[
end:</li>
 
Regex performance depends on the complexity of the search pattern. If you
search for a fixed pattern, to compare it's speed with IndexOf, Regex'es are
faster (than IndexOf) on long strings. (personal experience)

Niki

Bill Yin said:
Which faster using indexOf or RegularExpressions?


Justin Rogers said:
Unless you need resiliency in the pattern, you are better of using IndexOf.
By resiliency, I mean the ability to handle tags that aren't formed as well
as you demonstrate below.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


Bill Yin said:
I want get the Matchs
<li>[xxxxxxxxxxxxxxxxxxxxxxxxx</li>
begin:<li>[
end:</li>
 
Back
Top