Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove additional spacing in string [Fastest Way]
    primarykey
    data
    text
    <p>I need to remove all additional spaces in a string. I use regex for matching strings and matched strings i replace with some others. For better understanding please see examples below:</p> <p>3 input strings: </p> <pre><code>Hello, how are you? Hello , how are you? Hello , how are you ? </code></pre> <p>This are 3 strings that should match by one pattern-regex. It looks something like this:</p> <pre><code>Hello\s*,\s+how\s+are\s+you\s*? </code></pre> <p>It works fine but there is a perfomance problem. If I have a lot of patterns (~20k) and try to execute each pattern it runs very slow (3-5 minutes).</p> <p>Maybe there is better way for doing this? for example use some 3d-party libs?</p> <p><strong>UPD: Folks, this question is not about how to do this. It's about how to do this with best perfomance. :)</strong></p> <hr> <p>Let me explain more detailed. The main goal is tokenize text. (replace some token with special symbols)</p> <p>For example I have a token "nice try". Then I input text "this is nice try". result: "this is @tokenizedtext@" where @tokenizedtext@ some special symbols. It doesen't matter in this case.</p> <p>Next I have string "Mike said it was a nice try". result should be "Mike said it was a @tokenizedtext@". I think the main idea is clear.</p> <p>So I can have a lot of tokens. When I process it I convert my token from "nice try" to pattern "nice\s+try". and try to replace with this pattern input text. It works fine. But if in tokens there is more spaces and there is also punctuation then my regexes became bigger and works very slow.</p> <p>Do you have some suggestions (technical or logic) for solving this problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload