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?
Asked
Active
Viewed 211 times
0

The Student
- 27,520
- 68
- 161
- 264
-
2Use `/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
-
3An 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
-
2If 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 Answers
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
-
OP uses `\t*` inside a longer pattern. Changing to `\t+` might not be what is really necessary. – Wiktor Stribiżew Apr 30 '16 at 09:34
-
@WiktorStribiżew this is not specified in the question and I've noticed your comment to late. Why didn't you posted it as an answer? – Harms Apr 30 '16 at 09:53
-
@Harms you say for `\t*` that "nothing in regexp will match anything", but it does match tabs on the beggining of first line. – The Student Apr 30 '16 at 09:57
-
@Harms "nothing in regexp will match anything" this is not true. Nothing will match nothing only. – J Singh Apr 30 '16 at 10:05
-
1@JAtwal: A regex that can match nothing will match everywhere; I believe that's what Harms meant. – Alan Moore Apr 30 '16 at 12:11
-