官术网_书友最值得收藏!

  • Java 9 Regular Expressions
  • Anubhava Srivastava
  • 232字
  • 2021-07-02 18:58:33

What type of problems need regular expressions to solve

Some programmers wonder why they even need to learn regular expressions. Here are some use cases:

  • While searching for some text at times, there are cases where we don't know the value of the text upfront. We just know some rules or patterns of the text. For example, searching for a MAC address in a log message, searching for IP address in a web server access log, or searching for a 10-digit mobile number that may be optionally preceded by 0 or +<2 digit country code>.
  • Sometimes, the length of the text we are trying to extract is unknown, for example, searching URLs that start with http:// or https:// in a CSV file.
  • Sometimes, we need to split a given text on delimiters of a variable type and length and generate tokens.
  • Sometimes, we need to extract text that falls between two or more search patterns.
  • Often, we need to validate the various forms of user inputs, such as bank account number, passwords, usernames, credit card info, phone number, date of birth, and so on.
  • There are situations where you only want to capture all the repeated words from a line.
  • To convert input text into certain predefined formats, such as inserting a comma after every three digits or removing commas inside parentheses only.
  • To do a global search replace while skipping all the escaped characters.
主站蜘蛛池模板: 乐安县| 屯留县| 崇信县| 双牌县| 浙江省| 芦山县| 遂川县| 来宾市| 巴彦淖尔市| 泸西县| 东丰县| 大冶市| 边坝县| 寻乌县| 怀化市| 鄢陵县| 德江县| 泾阳县| 阿勒泰市| 包头市| 昌黎县| 襄樊市| 德昌县| 巴青县| 旌德县| 漠河县| 进贤县| 余姚市| 安泽县| 高阳县| 鄂伦春自治旗| 怀化市| 永吉县| 洪雅县| 大埔县| 松阳县| 平顺县| 隆子县| 长乐市| 邹平县| 监利县|