Калькулятор регулярных выражений java

Regex Tester

CyrilEx is an online regex debugger, it allows you to test regular expression in PHP (PCRE), Python, Ruby, JavaScript, Java and MySQL. It helps you to test and debug regex online, you can visualize the matches when matching a string against a regex.

A regex visualizer allows to visualize your regex, it helps to understand it. This feature is useful for large regexes.

Cyrilex also allows you to generate a string example from a RegEx. This gives a pretty quick idea of a regex.

You can consult the regex Quick Start or see the full user guide to help you to use this regular expression tester.

User guide

  • Step 0: Choose the regex engine: JavaScript, Ruby, Java or PCRE (PHP, Python).
  • Step 1: Copy and paste or directly type your regular expression to test in the «Regular expression to test» field.
  • Step 2: Select the flags you want in «Flags» section.
  • Step 3: Copy and paste or directly type your test string in the «test string» field.
  • As soon as you make a modification (regular expression, flags or test string):
    • Step 4: An explanation is generated about of your regex. It uses regulex, it is a JavaScript Regular Expression Parser & Visualizer (Written in pure JavaScript).
    • Step 5: A message indicates the number of correspondence
    • Your regex is highlighted according to the syntax. It is a beta version, it can be wrong.

    regex tester user guide

    regex tester user guide

    share regex tester

    Generate a string from RegEx (Beta):
    Clicks on «Generate a string from RegEx (Beta)» in order to generate a string that matches with the regex.

    Substitutions are not managed.

    News: You can now test MySQL regex, select the «MySQL 8» engine.

    About regular expression

    A regular expression is a sequence of characters that define a search pattern. This pattern is used by string searching algorithms for find or replace text. It can be useful to validate an EMAIL address or an IP address.

    Regex support is part of the standard library of many programming languages. Each programming language has its own regex engine, regular expression implementations vary slightly between languages.

    Regex humor (Jamie Zawinski):
    Some people, when confronted with a problem, think «I know, I’ll use regular expressions.» Now they have two problems.

    Regex Online

    Cyrilex is an online regex checker, it allows to easily test and debug regex. This avoids wasting time writing the few lines of code needed to do the tests.

    A regex visualizer and a regex generator help you to understand and debug your regexes.

    This tool also allows you to share your regular expressions, this can be useful when you want to explain one of your regex problems (or its resolution) on a forum.

    Regex Generator

    Cyrilex also allows generating string from your Regex. By generating a string, this can help understand the Regex. This is particularly useful for fairly long regex.

    This is also useful in the opposite direction. You can validate that your regex is correct by validating that the thong generated corresponds to the expected.

    This tool does not manage all the features of the Regex.

    The unavoidables

    Some regex that can be useful (without warranty).

    The last RFC is complex, there is no reliable solution, this regex should work more than 99% of the time (You must turn off case sensitivity).

    The regex below allows to validate alphanumeric string. Be careful, \w authorizes the underscore character.

    The regex below allows to validate MD5 string.

    The regex below allows to validate IP v4.

    Источник

    Want to support RegExr? Consider disabling your ad-blocker for this domain. We’ll show a non-intrusive, dev-oriented ad in this area.

    Expression

    Create new tests with the ‘Add Test’ button. Click a test to edit the name, type, & text.

    Tools

    RegEx Engine

    Expression Flags

    Sign In

    Sign in to persist favorites & patterns. Click the help icon above for info.

    Any unsaved changes will be lost. Saved patterns & favorites will be migrated to your account.

    Sign Out

    You are currently signed in as via .

    Character classes
    . any character except newline
    \w \d \s word, digit, whitespace
    \W \D \S not word, digit, whitespace
    [abc] any of a, b, or c
    [^abc] not a, b, or c
    [a-g] character between a & g
    Anchors
    ^abc$ start / end of the string
    \b \B word, not-word boundary
    Escaped characters
    \. \* \\ escaped special characters
    \t \n \r tab, linefeed, carriage return
    Groups & Lookaround
    (abc) capture group
    \1 backreference to group #1
    (?:abc) non-capturing group
    (?=abc) positive lookahead
    (?!abc) negative lookahead
    Quantifiers & Alternation
    a* a+ a? 0 or more, 1 or more, 0 or 1
    a a exactly five, two or more
    a between one & three
    a+? a? match as few as possible
    ab|cd match ab or cd

    Источник

    Java Regular Expression Tester

    This free Java regular expression tester lets you test your regular expressions against any entry of your choice and clearly highlights all matches. Consult the regular expression documentation or the regular expression solutions to common problems section of this page for examples.

    Regular Expression — Documentation

    • Used to indicate that the next character should NOT be interpreted literally. For example, the character ‘w’ by itself will be interpreted as ‘match the character w’, but using ‘\w’ signifies ‘match an alpha-numeric character including underscore’.
    • Used to indicate that a metacharacter is to be interpreted literally. For example, the ‘.’ metacharacter means ‘match any single character but a new line’, but if we would rather match a dot character instead, we would use ‘\.’.
    • Matches the beginning of the input. If in multiline mode, it also matches after a line break character, hence every new line.
    • When used in a set pattern ([^abc]), it negates the set; match anything not enclosed in the brackets
    • Matches the preceding character 0 or 1 time.
    • When used after the quantifiers *, +, ? or <>, makes the quantifier non-greedy; it will match the minimum number of times as opposed to matching the maximum number of times.

    Regular Expression — Solutions to common problems

    How can I emulate DOTALL in JavaScript?

    DOTALL is a flag in most recent regex libraries that makes the . metacharacter match anything INCLUDING line breaks. JavaScript by default does not support this since the . metacharacter matches anything BUT line breaks. To emulate this behavior, simply replaces all . metacharacters by [\S\s]. This means match anything that is a single white space character OR anything that is not a white space character!

    How to validate an EMAIL address with a regular expression?

    There is no 100% reliable solution since the RFC is way too complex. This is the best solution and should work 99% of the time is. Consult this page for more details on this problem. Always turn off case sensitivity!

    How to validate an IP address (IPV4) with a regular expression?

    This will make sure that every number in the IP address is between 0 and 255, unlike the version using \d which would allow for 999.999.999.999. If you want to match an IP within a string, get rid of the leading ^ and trailing $ to use \b (word boundaries) instead.

    ^(?:(?:253|217|[01]?43?)\.)(?:252|248|[01]?62?)$
    How to validate a DATE with a regular expression?

    Never use a regular expression to validate a date. The regular expression is only useful to validate the format of the date as entered by a user. For the actual date validity, it’s better to rely on actual code.

    The following expressions will validate the number of days in a month but will NOT handle leap year validation; hence february can have 29 days every year, but not more.

    ISO date format (yyyy-mm-dd)

    ^8-(((0[13578]|(10|12))-(03|26|31))|(02-(03|26))|((0[469]|11)-(01|22|30)))$

    ISO date format (yyyy-mm-dd) with separators ‘-‘ or ‘/’ or ‘.’ or ‘ ‘. Forces usage of same separator across date.

    ^7([- /.])(((0[13578]|(10|12))\1(09|19|31))|(02\1(07|18))|((0[469]|11)\1(03|16|30)))$

    United States date format (mm/dd/yyyy)

    ^(((0[13578]|(10|12))/(01|11|31))|(02/(02|17))|((0[469]|11)/(07|15|30)))/7$

    Hours and minutes, 24 hours format (HH:MM)

    How to validate NUMBERS with a regular expression?

    It depends. What type of number? What precision? What length? What do you want as a decimal separator? The following examples should help you want with the most common tasks.

    Positive integers of undefined length

    Positive integers of maximum length (10 in our example)

    Positive integers of fixed length (5 in our example)

    Negative integers of undefined length

    Negative integers of maximum length (10 in our example)

    Negative integers of fixed length (5 in our example)

    Integers of undefined length

    Integers of maximum length (10 in our example)

    Integers of fixed length (5 in our example)

    Numbers of undefined length with or without decimals (1234.1234)

    Numbers with 2 decimals (.00)

    Currency numbers with optional dollar sign and thousand separators and optional 2 decimals ($1,000,00.00, 10000.12, 0.00)

    ^$?\-?(89(\,\d)*(\.\d)?|6\d(\.\d)?|0(\.\d)?|(\.\d))$|^\-?$?(4\d(\,\d)*(\.\d)?|4\d(\.\d)?|0(\.\d)?|(\.\d))$|^\($?(3\d(\,\d)*(\.\d)?|9\d(\.\d)?|0(\.\d)?|(\.\d))\)$

    Percentage from 0 to 100 with optional 2 decimals and optional % sign at the end (0, 0.00, 100.00, 100%, 99.99%)

    How to validate feet and inches with a regular expression?

    The notation for feet and inches is F’I». Possible values would be 0’0″, 6’11», 12456’44»

    How to validate an hexadecimal color code (#FFFFFF) with a regular expression?

    The leading # sign is optional and the color code can take either the 6 or 3 hexadecimal digits format.

    How to check for ALPHANUMERIC values with a regular expression?

    You could make use of \w, but it also tolerates the underscore character.

    How to validate a SSN (Social Security Number) with a regular expression?

    Unlike many other similar numbers such as the canadian social insurance number (SIN) there is no checksum for a SSN. Validating the format of the SSN does not mean it’s valid per say though.

    How to validate a SIN (Social Insurance Number) with a regular expression?

    This will only validate the format. A SIN should also be validated by computing the checksum digit. This regex will tolerate the form XXX XXX XXX, XXXXXXXX or XXX-XXX-XXX. Note that the group separator must be the same.

    How to validate a US Zip Code with a regular expression?

    The United States Postal Services makes use of zip codes. Zip codes have 5 digits OR 9 digits in what is known as a Zip+4.

    Zip Code (99999)

    Zip and Zip+4 (99999-9999)

    How to validate a Canadian Postal Code with a regular expression?

    The Canadian Postal Services uses postal code. The postal codes are in format X9X 9X9. This will tolerate a space between the first and second group.

    ^[ABCEGHJKLMNPRSTVXY]\d[A-Z] *\d[A-Z]\d$
    How to extract the filename in a windows path using a regular expression?

    Since every part of a path is separated by a \ character, we only need to find the last one. Note that there’s just no way to check if the last portion of a path is a file or a directory just by the name alone. You could try to match for an extension, but there’s no requirement for a file to have an extension.

    How to validate a US or Canadian telephone number using a regular expression?

    There are probably dozens of way to format a phone number. Your user interface should take care of the formatting problem by having a clear documentation on the format and/or split the phone into parts (area, exchange, number) and/or have an entry mask. The following expression is pretty lenient on the format and should accept 999-999-9999, 9999999999, (999) 999-9999.

    How to validate credit cards using a regular expression?

    Again, you should rely on other methods since the regular expressions here will only validate the format. Make use of the Luhn algorithm to properly validate a card.

    American Express

    Diners Club

    How do I strip all HTML tags from a string?

    Make sure to be in global mode (g flag), case insensitive and to have the dot all option on. This regular expression will match all HTML tags and their attributes. This will LEAVE the content of the tags within the string.

    How can I remove all blank lines from a string using regular expression?

    Make sure to be in global and multiline mode. Use an empty string as a replacement value.

    Источник

    Читайте также:  Реализация очередь в java
Оцените статью