noobed noobed - 2 months ago 7
Javascript Question

javascript regex exclude dot

Hello I'm finding difficulties making the right regex. I'm missing something, but I don't know what.

pattern:

href=".*?\/FileBrowser\/File\?path=esoft\/[^.\s]*?"


test string:

dfhgndfhkljh;fth href="/FileBrowser/File?path=esoft/test/I4/I0000/as.jpeg" dfghfdhnjfgh e:small;"><a href="/FileBrowser/File?path=esoft/test/bb/2evo/1_folder" target="_blank"dsadsadsa


and the site I use to test online is https://regex101.com/r/mU5vH6/2

The goal is to mark the links (after the href) separately as shown https://regex101.com/r/mU5vH6/3 here, but if one of them has a dot - meaning file path, not to be included

Answer

You can use this regex:

href="[^"]*\/FileBrowser\/File\?path=esoft([^.])*?"

The previous one was matching:

dfhgndfhkljh;fth href="/FileBrowser/File?path=esoft/test/I4/I0000/as.jpeg" dfghfdhnjfgh e:small;"><a href="/FileBrowser/File?path=esoft/test/bb/2evo/1_folder" target="_blank"dsadsadsa
                 |___________________________________________________________________________________________________________________________________________|

Because you allowed your match to contain ", which consumed too much chars