0

If you try on http://regexr.com/ the regex \t you get all the single tabs. But if you try \t* you get only on the beginning of the first line. Why?

The Student
  • 27,520
  • 68
  • 161
  • 264
  • 2
    Use `/g` flag and you will match all. Certainly you need `\t+` though as `\t*` can match an empty string and will match at each location in string. Hint: use regex101.com for better user experience. – Wiktor Stribiżew Apr 30 '16 at 09:04
  • @WiktorStribiżew I want, in the middle of my regex, zero or more tabs. But the `\t*` is not working... What's wrong in using `\t* *` (zero or more tabs, zero or more spaces)? – The Student Apr 30 '16 at 09:07
  • 3
    An XY problem? Update the question with what issue you really have. – Wiktor Stribiżew Apr 30 '16 at 09:09
  • @WiktorStribiżew actually, my real problem is already solved. I just would like to understand now why `\t*` matches only the beginning of first line, while `\t` matches all text tabs. – The Student Apr 30 '16 at 10:01
  • If you want any clear answer, you should make your quedtion clear, so that it can be answered. Do not refer to online testers, just provide an exact input string, what pattern you use, what you expect. You comment above is unclear. – Wiktor Stribiżew Apr 30 '16 at 10:34
  • 2
    If you've tested this on [RegExr](http://regexr.com/3db5m), you must have seen the bright red "infinite" icon over to the right. That means your regex can match zero characters, which is apparently not allowed on that site. So it's the tool that's broken, not your regex. Try it on [Regex101](https://regex101.com/r/gX0pJ6/1) instead, and you'll see it matches virtually everywhere, not just the beginning. – Alan Moore Apr 30 '16 at 12:09
  • @AlanMoore oh gosh... Thanks! Please, post as an answer. – The Student Apr 30 '16 at 17:06

1 Answers1

0

If you use \t* only, then you trying to match nothing, one or more tabs. Nothing in regexp will match anything, so it won't work. If you need to find one or more tabs, use \t+ instead. To make your regexp work on all lines, use global setting. There is an example: http://regexr.com/3db4i

Harms
  • 69
  • 4