Search code examples
regexeditpad

How do I start at the first non blank character of a line (Regex)


I want Regex to start at the first word/number that isn't blank. In my example below, I want to start at LG. There are lots of other lines of a near identical structure I will also have to match through.

    <div class="p13n-sc-truncate p13n-sc-truncated-hyphen p13n-sc-line-clamp-2" aria-hidden="true" data-rows="2" data-truncate-mix-weblab='true'>

        LG 32MA68HY-P 32-Inch IPS Monitor with Display Port and HDMI Inputs

My Regex is.. (?<='True'>\n).*.(?=\n)

Rather than adding a lot of dots is there a way to start at the first letter/number/word for this line?

I believe [^\s] should work but I can't get it working..


Solution

  • EditPadPro from JG Software is powered with a regex engine that supports infinite width lookbehind.

    You may use a positive lookbehind that makes sure there is a 'true'> substring followed with a newline and 0+ whitespaces immediately to the left of the current location. Then, you may just consome a non-whitespace char followed with any 0+ chars other than newline.

    Here is an example:

    (?<='true'>\r?\n\s*)\S.*
    

    See the regex demo

    If the char should be a word char, replace \S with \w.

    Details:

    • (?<='true'>\r?\n\s*) - a positive lookbehind that makes sure there is a 'true'> substring followed with an optional CR and then an LF and 0+ whitespaces immediately to the left of the current location
    • \S - any non-whitespace char
    • .* - any 0+ chars other than newline as many as possible.