Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6042883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:50:21+00:00 2026-05-23T06:50:21+00:00

I’m using regex snippets to parse smileys into images, and encountering problems with the

  • 0

I’m using regex snippets to parse smileys into images, and encountering problems with the semicolon. For example, a smiley like 😉 turns into a WINK icon, matching against

/;-?\)/g

and works in most cases. But text like “) is also matching into “WINK, because the quotation mark is actually an html entity (" => &quotWINK).

I tried prefixing the regex with a greedy non-capturing match to discard semicolons in entities:

(?:"|&|<|>|'|')?

But the resulting pattern still matches against the semicolon in " that should be skipped, because it backtracks to satisfy the non-optional latter portion. I also realized there’d still be problems with other legitimate matches, such as EVIL: >:) => >:).

So what it appears I really need is the negation of preceding html entities missing a semicolon:

(?!&quot|&amp|&lt|&gt|&apos|&#039)

But it is still matching and I’m not sure why.

It would be ideal to still get returned matches that can be replaced wholesale without further inspection, but I’m open to suggestions. What is not suitable is first parsing out the html entities, because sometimes they’re necessary and/or part of a legitimate smiley (as with EVIL).


EDIT (some Google food):

I discovered (and Bryan also noted below) that Zero-width positive lookbehind, (?<!regex), would work as desired (not Zero-width negative lookahead (?!regex)).

As per regular-expressions.info, the latter “will only succeed if the regex inside the lookahead fails to match” which sounds right, but isn’t when the section is optional anyway.

In contrast, the former “matches at a position if the pattern inside the lookahead can be matched ending at that position” which isn’t at all clear, but does the trick. Because the match is using lookbehind, there’s no chance of backtracking to satisfy the latter portion of the regex.

So a full regex looks like:

/(?<!&quot|&amp|&lt|&gt|&apos|&#039);-?\)/g

and that matches these: ;) => WINK blah;) => blahWINK &quot;;) => &quot;WINK while failing this: &quot;)
It does however still match &amp;quot;) => &amp;quotWINK, so more tweaking would be ideal (such as additionally matching semicolons in place of the ampersands, if that doesn’t cause other smileys with entities in them to break). People typing out html entities in chat isn’t likely to come up much anyway.

Either way would be “good enough”–except that javascript doesn’t support negative lookbehind. But it’s worth explaining for the sake of other regex implementations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:50:22+00:00Added an answer on May 23, 2026 at 6:50 am

    First off, you could just check for whitespace characters preceding the ;-), so that’s a simpler option. But if you do want to implement negative lookbehind in JavaScript — which exists in several flavors of regex but not in the JS one — you could do something like this:

    var text = "& &amp; &amp;-) ;-) test;-)";
    var ENTITIES_REGEX = /(&quot|&amp|&lt|&gt|&apos|&#039)?;-\)/g;
    
    var result = text.replace(ENTITIES_REGEX, function(fullMatch, backref1) {
      // Ignore if there is a backreference by returning the unaltered
      // match, otherwise return WINK
      return (backref1 ? fullMatch : 'WINK');
    });
    
    // result equals "& &amp; &amp;-) WINK testWINK"
    

    And here’s an example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.