There are often subtleties to patterns posted that baffle me. So nice to have a welcoming community that I can learn from. So thanks indeed Neil and Kaveh.
On Saturday, October 28, 2023 at 7:16:50 AM UTC-7 Kaveh Bazargan wrote: > Thank you for the detailed response Neil. I stand corrected on that > detail. I normally use regex directly so no need to escape... > > Of course regex is already a headache to read, and escaping backslashes > etc makes it doubly so... > > Regards > Kaveh > > On Sat, 28 Oct 2023 at 15:05, Neil Faiman <[email protected]> wrote: > >> On Oct 28, 2023, at 6:29 AM, Kaveh Bazargan <[email protected]> wrote: >> >> But I believe that in other environments, e.g. other programming >> languages, you sometimes need to escape. I think sometime with \" and >> sometimes "" >> >> >> The problem is that >> >> >> - Regular expressions themselves are a moderately complex language >> with a specific syntax, but >> - Regular expressions are often used in other languages, where they >> may also be subject to the syntax rules of those languages. >> >> >> The only things that need to be “escaped” in the regular expression >> language are the regular expression special marker characters: parentheses, >> dots, plus signs, asterisks, question marks, brackets, backslashes, some >> letters … >> >> When you use a regular expression in BBEdit, in a Find and Replace dialog >> or one of the special Text menu operations, you are just writing a regular >> expression, so only the regular expression language rules apply, and the >> only things that need to be escaped are the regular expression operator >> characters. (Single backslashes before other characters generally are just >> ignored, like the backslashes before the quote marks in this example; but >> best practice is probably to use only the backslashes that are required by >> the regular expression syntax.) >> >> But, for example, when you use a regular expression in the Perl language, >> the regular expression (often) has slashes around it to show that it is a >> regular expression, so if there are slashes in the regular expression, they >> need to be escaped. >> >> In some languages, a regular expression is just written as a a string >> literal, which means that it has to satisfy the language rules for a string >> literal. In particular, backslashes are special in string literals in the >> C-family languages, which means that any backslashes in a string literal >> have to be escaped, as well as any quote marks, which otherwise would mark >> the end of the string. >> >> Thus, the regular expression (.+"ERROR".+)\r(.+)\r(.+)\r(.+) as a string >> literal in C would be "(.+\”ERROR\".+)\\r(.+)\\r(.+)\\r(.+)” where the >> red backslashes are needed so that the quotes around ERROR won’t look like >> the end of the string, and so that the character sequence \r is part of >> the regular expression (otherwise, the \r would be transformed into a >> carriage-return character by the C string literal parser, and the regular >> expression would contain return characters instead of backslash-r >> sequences). >> >> Regards, >> Neil Faiman >> >> -- >> This is the BBEdit Talk public discussion group. If you have a feature >> request or need technical support, please email "[email protected]" >> rather than posting here. Follow @bbedit on Twitter: < >> https://twitter.com/bbedit> >> --- >> You received this message because you are subscribed to the Google Groups >> "BBEdit Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/bbedit/2FED3052-5F34-48B3-BA87-648A196B61BB%40faiman.org >> >> <https://groups.google.com/d/msgid/bbedit/2FED3052-5F34-48B3-BA87-648A196B61BB%40faiman.org?utm_medium=email&utm_source=footer> >> . >> > > > -- > Kaveh Bazargan PhD > Director > River Valley Technologies <http://rivervalley.io> ● Twitter > <https://twitter.com/rivervalley1000> ● LinkedIn > <https://www.linkedin.com/in/bazargankaveh/> ● ORCID > <https://orcid.org/0000-0002-1414-9098> ● @[email protected] > <https://mastodon.social/@kaveh1000> > *Accelerating the Communication of Research* > > * > <https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop> > [image: > https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/] > > <https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/>* > -- This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "[email protected]" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit> --- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/a56318e9-006a-476a-8eb5-e7ce31d615ffn%40googlegroups.com.
