Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

In a recent question (Remove whitespaces in a stringRemove whitespaces in a string) my solution included using a simple regex replacement (\\s+) to match all instances of double spaces (or more) and reduce them to a single space.

While this works great its been bugging me that the code might not be a little more efficient to use (\\s\\s+) as this would reduce the number of matches requiring replacement.

Short Question

Is it more efficient to use a more complex regex match when doing a replaceAll()

In a recent question (Remove whitespaces in a string) my solution included using a simple regex replacement (\\s+) to match all instances of double spaces (or more) and reduce them to a single space.

While this works great its been bugging me that the code might not be a little more efficient to use (\\s\\s+) as this would reduce the number of matches requiring replacement.

Short Question

Is it more efficient to use a more complex regex match when doing a replaceAll()

In a recent question (Remove whitespaces in a string) my solution included using a simple regex replacement (\\s+) to match all instances of double spaces (or more) and reduce them to a single space.

While this works great its been bugging me that the code might not be a little more efficient to use (\\s\\s+) as this would reduce the number of matches requiring replacement.

Short Question

Is it more efficient to use a more complex regex match when doing a replaceAll()

Tweeted twitter.com/#!/StackSalesforce/status/251698716254281729
Source Link
Jon Hazan
  • 2.9k
  • 18
  • 29

Regex replacement efficiency

In a recent question (Remove whitespaces in a string) my solution included using a simple regex replacement (\\s+) to match all instances of double spaces (or more) and reduce them to a single space.

While this works great its been bugging me that the code might not be a little more efficient to use (\\s\\s+) as this would reduce the number of matches requiring replacement.

Short Question

Is it more efficient to use a more complex regex match when doing a replaceAll()