Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDITED</strong> (see after blockquote)</p> <blockquote> <p>I don't have commenting privileges, so I can't comment on his solution, but Qtax's solution will not work because it assumes that <code>begin</code> will never contain the substring "end", e.g., it wouldn't match the string "sendingend".</p> <p>My solution: <code>^([A-Za-z0-9]*)(?:end)?$</code></p> <p>Of course, it also depends on what you mean by <em>alphanumeric</em>. My example has the strictest definition, i.e., just upper- and lower-case letters plus digits. You'd need to add in other characters if you want them. If you want to include the underscore as well as those characters, you can replace the whole bulky <code>[A-Za-z0-9]</code> with <code>\w</code> (equivalent to <code>[A-Za-z0-9_]</code>). Add <code>\s</code> if you want whitespace.</p> <p>Since you said your regex knowledge is limited, I'll explain the rest of the solution to you and whoever else comes along.</p> <ul> <li><code>^</code> and <code>$</code> match the beginning and the end of the string, respectively. <strike>By including the <code>$</code> in particular, you're guaranteeing that the last "end" you encounter is really at the end. For example, without them, it would still match the string "sendingsending" and the rest of your program would think it's found that "end" at the end. With these, it's still going to match "sendingsending" because any characters are allowed (see below), but other steps in your script will recognize the presence of "end".</strike> It actually doesn't matter much for this current string, because the <code>([A-Za-z0-9]*)</code> will capture the entire string if "end" is not present. However, you therefore need another regex to ensure the presence or absence of "end"...so you'd do something like <code>(end)$</code> to locate it. </li> <li><code>([A-Za-z0-9]*)</code>: the square brackets contain the specific characters that are allowed (you should definitely read up on this if you don't know). The <code>*</code> means it will match one of those characters 0 or more times, so this allows for no string (i.e., just "end") as well as super-long strings. The parentheses are capturing that pattern so you can back-reference it. </li> <li><code>(?:end)?</code>: the last <code>?</code> makes it match this pattern 0 or 1 times (i.e., makes it optional). The <code>(?:string)</code> structure allows you to group characters together as you would with parentheses but the <code>?:</code> makes it <em>not</em> save that pattern, so it uses less memory. In your case, that memory would be negligible, but it's nice to know for future use.</li> </ul> <p>If you need more help, try Googling 'regex'. There's tons of good references. You can also test them out. My personal favourite tester is called <a href="http://myregextester.com/index.php" rel="nofollow">My Regex Tester</a>.</p> <p>Good luck!</p> </blockquote> <p>I just tried looking up TextPad macros, and you might run into a problem. As I've explained above, to verify the presence of "end" at the end of the string, you'll need something separate. I was envisioning some kind of conditional, something like IF <code>(end)$</code> THEN replace with <code>^([A-Za-z0-9]*)(?:end)?$</code> ELSE use the whole string. However, I don't know if you can do that with these macros...it's hard to say, because I'm not a TextPad user and there's next to no documentation. If you can't, then I think you're going to have to put some restrictions on it. One idea is to not allow "end" to be anywhere in the <code>begin</code> substring (which is how Qtax's solution did it). But now I'm wondering...if "end" if going to be optional, and if conditionals aren't allowed, what's the point of having it at all? ...perhaps I'm overthinking things. I await your reply.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload