I have a string. The string can contain spaces, Latin characters and symbol $.
Example: tert ertert$sdfsdf
But, symbol $ must be surrounded only with characters, not spaces.
Good string: "teststring$sdfsdf"
Bad string: "test $sdfsdf"
Bad string "test $ string"
How can i make regular expression for this string?
Thank you
Not sure what language you need this for, but this will work
/\s+\$|\$\s+/to match the “bad” scenario.The logic is
So, if this were Java it would look like:
In Perl, it would be:
I recommend asking more specifically for a language example cause these do tend to vary a bit from use to use.
Also, the people on this site tend to feel that you should have tried to solve this on your own before coming here for help. So, if you want to avoid seeing snarky comments about what have you already attempted, you should offer your failed attempts as a sacrifice to the petulant forces that be :). Just asking “how do I do this” does leave the person answering with a quandary as to “where do I begin… what do you already know, where are you actually stuck, etc.”.