Author Topic: Find first instance of ';' or '{'  (Read 4357 times)

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
Find first instance of ';' or '{'
« on: November 01, 2016, 07:59:39 PM »
This piece of code works good to find the end of a statement. I'm wondering if it can be changed to search for the first instance of either ';' or '{'. Any good way to do that:
// Find end of statement. This handles multiple-line statements.
   search(";","@hXcs");

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
Re: Find first instance of ';' or '{'
« Reply #1 on: November 01, 2016, 10:21:44 PM »
Hmm I think I've figured this one out myself:
   
Code: [Select]
if (search("[;|{]","+>R?")) stop();
I did want to ask though, how do I escape a quote string on regular search expressions with slickedit reg expressions. I have tried '" and \" and neither worked.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6866
  • Hero Points: 528
Re: Find first instance of ';' or '{'
« Reply #2 on: November 04, 2016, 11:30:49 AM »
Hmm I think I've figured this one out myself:
   
Code: [Select]
if (search("[;|{]","+>R?")) stop();
I did want to ask though, how do I escape a quote string on regular search expressions with slickedit reg expressions. I have tried '" and \" and neither worked.
It's better to use single quoted strings for regular expressions.

Double quoted regex search for backslash: "\\\\"
Single quoted regex search for backslash: '\\'