java - How to determine the static part of a regular expression at the beginning? -


is there safe way determine part of regular expression static i.e. matches 1 string?

i have regular expression file paths , want extract part @ beginning doesn't require regular expression can perform direct search speed performance.

for example:

  • /some/path/.*\.jpg => /some/path/ , .*\.jpg
  • /files/[0-9a-f]{32}/.* => /files/ , [0-9a-f]{32}/.*
  • .* => empty string , .*
  • /abc\.data/.* => /abc.data/ , .*

edit

the pattern have valid form. maybe doesn't have static part @ beginning times does.

edit 2

my application getting file path , searches pattern in database matches file path. table contains information should done file. however, searching pattern takes lot of time when match every string because have scan whole table. if extract static part @ beginning limit number of patterns have check.

supposing correctness of input, can split string (regex) @ first occurence of char, "keyword" regex. way, can static part of regex, , real regex.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -