-2

I am trying to make three regex: The first one allows the following, but not allow the other two

1.1.1whatever
1.2.3balabala

The second one allows the following, but not allow the other two

3.2xxxx
4.1anything

The thid one allows the following, but not allow the other two

1Title
3name
李晓恩
  • 23
  • 3
  • Whats difference between the 3 regexs? – Zahid Khan Aug 19 '20 at 04:37
  • Needs clarification. – Zahid Khan Aug 19 '20 at 04:39
  • Which tool or which language are you using? Do you use it in MS Office vba? – Light Aug 19 '20 at 05:50
  • Welcome to Stack Overflow. Please find yourself some help at [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean). If you want us to help with your particular issue, you should provide more detail, particularly, what you're trying to match (verbally described when possible, and not just examples), what RegEx are you trying to use and where your attempted solution fails to match. – Marc Sances Aug 19 '20 at 06:17
  • It's used in MS office vba. These regulars are used for heading1, heading2 and heading3. For instance "2.3ChapterName", I've tried "^\d+\.\d+[^\.]" , but it will not only match "2.3" but also "2.3C" – 李晓恩 Aug 19 '20 at 13:47

1 Answers1

0

Based on my knowledge of vim and perl, I managed to complete the following regex to match your titles

"^\d+(\.\d+){X}\s*\w+"

You can change the X to specify how many succeeding "<dot><digits>" pairs you still want to match.

For example, "^\d+(\.\d+){2}\s*\w+" will match 1.2.3title but not 1.2title.

Light
  • 1,089
  • 1
  • 8
  • 15
  • Really thanks. By the way, if someone want to seperate `1.2.3title` as `1.2.3` and `title` based on the reg, you can use `^\d+(\.\d+){2}(?!\.\d+)` – 李晓恩 Aug 20 '20 at 02:19