Match 2 character next to each other regex

964 views javascript

I'm newbie in regex. I want create a regex for:

  • Match '--' in first
  • Match '$' in last
  • Match '=$' next to each other.

Here is something I try to match '--' in first and '$' in last but not work


String I want to pass this regex: --hostname=$HOSTADDRESS$

How can I do that. Please help me

answered question

Do you mean like this: /--(.*)=\$(.*)\$/? You can leave off the brackets if you don't need to capture the groups.

@david you should have anchors on your regex

@david thanks you

@Nick there's not enough info in the question to decide if OP wants it anchored at the ends like the example given, or anchored by spaces like I'd expect, or if lazy qualifiers would be sufficient. The meat of the regex is what they're struggling with and my comment was to clarify that point, not to provide an answer.

@david Just going on the basis that OP had them on their regex...

1 Answer



You need to include the m flag after /g to enable multiline ^ and $.

I don't know what you were trying to do with [--], but to match =$ you need to include =\$ in your regex.

posted this

Have an answer?


Please login first before posting an answer.