Regular Expression Algorithm

Something like this in my head: I put one or more lines, and the algorithm shows me the corresponding regular expression.

Is there any “easy” way to do this, or is something like that already exist?

Edit: Yes, I'm trying to find a way to generate a regular expression.

Edit: Regulases are not what I'm looking for. The usual use of the code I want is to find the correct regular expression, such as articlenumbers.
Example:

  • I set 123456, the regex should be \ d {6}
  • I put in nb-123456, the regex should be \ w {2} - \ d {6}
+3
source share
7 answers

Emacs, regexp-opt. , :

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

"list\\|my\\|of\\|s\\(?:earch\\|ome\\|trings\\)\\|to"
+3

, , , . - . , -, , .

txt2re - .

+2

( )?

. *

+1

, , (, jflex), , regex w.r.t. .

0

txt2re.

This site contains a form that takes an example string and generates a regular expression pattern that can match a given string.

Then it generates the appropriate script for the following languages: Perl, PHP, Python, Java, Javascript, ColdFusion, C, C ++ Ruby, VB, VBScript, J # .net, C # .net, C ++. net, VB.net

0
source

Source: https://habr.com/ru/post/1697970/


All Articles