-1

I want to match literal / character in regexp, so I use [/]. Using this example results in

/ An unescaped delimiter must be escaped with a backslash ()

Am I wrong or is the website wrong? As far as I know, all characters inside square brackets [] must be present as literal without escape character.

Please, clarify to me.

EDIT: I use MySQL. How is / should be presented if I want to meet literal /? Is using [/] the right thing? Or [\/]?

Emma
  • 27,428
  • 11
  • 44
  • 69
user9371654
  • 2,160
  • 16
  • 45
  • 78
  • 1
    What flavor/language? And no, brackets don't change the meaning of / since / is not part of the expression. It's an external delimiter. – Mad Physicist May 12 '19 at 17:43
  • 2
    If `/` is your default regex delimiter, then you need to escape it like `\/` doesn't matter whether it's inside charset or not. But if you change it like you can do in PHP, then you don't even need to escape it outside character class. – Pushpesh Kumar Rajwanshi May 12 '19 at 17:44
  • I am using MySQL. Plz note that I am talking about / inside square brackets as I want to match / literally. – user9371654 May 12 '19 at 17:45
  • But I use that site to test as it is difficult to test in large data base. – user9371654 May 12 '19 at 17:45
  • 1
    On regex101 you can change the delimiter (in this case the forward slash). In the input field where you enter the regex there are 3 vertical dots on the left. You can click it and change it to something else than the forward slash. – The fourth bird May 12 '19 at 17:56
  • 2
    @user9371654: In MYSQL db, you don't need to escape `/` and can write `/` as it is. Can you share what MYSQL db version you are using and what is your query that is leading you to this error? – Pushpesh Kumar Rajwanshi May 12 '19 at 17:58
  • @Pushpesh Kumar Rajwanshi I use MySQL workbench 8.0. I do not get any error in MySQL whether I use [/] or [\/]. I tested my regex in regex101 and foud that it requires [\/] and does not accept [/]. So I am worried that writing [\/] in MySQL will lead to something unintended, e.g. matching \ as well. So my understanding is that in MySQL I can use [/] and no need to escape. The issue of requiring escape is special to regex101 website. – user9371654 May 12 '19 at 18:20

2 Answers2

1

It depends what delimiter the used language used. It is the character / in many languages, so if you use a literal slash you need to escape it (like [\/]), or use different delimiter if possible in the language.

Ho Zong
  • 523
  • 1
  • 4
  • 22
1

The link you have provided it has a pattern error in it. If you wish to pass a forward slash you need a backslash before it in the char list. You might want to use [\/] in this site for testing and then remove it when you want to use in MySQL.

enter image description here

Correction

enter image description here

Metachars in MySQL

  • This post might help you about metachars in MySQL.

  • This answer also explains metachars in mysql.

  • This post explains how to escape meta chars in MySQL.

Community
  • 1
  • 1
Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    I understand. But I am surprised why this happened in that wesite? as I know that if I want to meet literal characters I put it as-is in the square brackets. I am confused what should I do in MySQL? should I put [/] literally or escape it [\/] like the website editor? – user9371654 May 12 '19 at 17:51