Reputation: 149
I want to develop a regex expression that matchs caracters, numbers or special caracters(!#$%&'*+-/=?^_`{|\}~
)
For example, valid strings are:
aaa456
4567777ertttt
!#$%&'*+-/=?^_`{|\}~ert788888
I have written this pattern :
val regex = "?: [a-zA-Z0-9]*[!#$%&'*+-/=?^_`{|\}~]*"
but it does not work in some cases :
!#$%&'*+-/=?^_`{|\}~ert788888
Have someone idea about that ?
Upvotes: 0
Views: 77
Reputation: 51271
OK, I might have come up with a pattern that meets your requirements as stated in the comments (the question itself lacks sufficient information to be useful).
This pattern matches any string that starts with a character that is not a dot, and that is followed by one or more characters that are either A) not a dot, or B) a dot that is not followed by a dot.
"[^.]([^.]|.(?!\\.))+"
With this you can test/validate strings of interest.
testString matches "[^.]([^.]|.(?!\\.))+" //returns true/false
Upvotes: 2