Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm to get a Regex

Tags:

regex

Something like this is on my mind: I put one or a few strings in, and the algorithm shows me a matching regex.

Is there an "easy" way to do this, or does something like this already exist?

Edit 1: Yes, I'm trying to find a way to generate regex.

Edit 2: Regulazy is not what I am looking for. The common use for the code I want is to find a correct RegEx; for example, article numbers:

  • I put in 123456, the regex should be \d{6}
  • I put in nb-123456, the regex should be \w{2}-\d{6}
like image 614
gamue Avatar asked Nov 17 '25 21:11

gamue


1 Answers

If you have Emacs you can use regexp-opt. For example, evaluating:

(regexp-opt (list "my" "list" "of" "some" "strings" "to" "search"))

returns

"list\\|my\\|of\\|s\\(?:earch\\|ome\\|trings\\)\\|to"
like image 107
Dave Webb Avatar answered Nov 20 '25 13:11

Dave Webb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!