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 7985129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:28:42+00:00 2026-06-04T11:28:42+00:00

I need to match all mentions without RT before. I’ve tried adding ! to

  • 0

I need to match all mentions without RT before. I’ve tried adding ! to negate the rt but don’t work.

preg_match( '/\b!rt\s*@([a-zA-Z0-9_]{1,20})/i', $string, $data );

this must match: ‘hello @user how are you’.
this not: ‘RT @user how are you’

Im not trying to extract usernames or something, what I need is to know if the text has @user without RT.

Any ideas?

  • 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-06-04T11:28:43+00:00Added an answer on June 4, 2026 at 11:28 am

    ! doesn’t “negate” in regex. That matches a literal !. What you want is a “Negative Lookbehind”.

    /(?<!RT)\s@([a-z0-9]{1,20})/i
    

    (?<!RT) means “not preceded by “RT”.

    This will match the username, the “RT” isn’t included as a match.

    $match = preg_match('/(?<!RT)\s@([a-z0-9]{1,20})/i', $string);
    

    If $match is 0, it means the string was “RT @user …”. If $match is not 0, that means the string did not start with “RT @user”.

    DEMO: http://ideone.com/bOWbu

    More info on regex lookarounds: http://www.regular-expressions.info/lookaround.html

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

Sidebar

Related Questions

I need to match all of these opening tags: <p> <a href="foo"> But not
I need to match all occurrences of // in a string in a Javascript
I need to match all the whole words containing a given a string. string
I need CSS selector that match all input tags where type is not checkbox
I need to match all urls that DO have mydomain.com in them AND DO
Is it possible to do string negation in regular expressions? I need to match
In short, I need to match all URLs in a block of text that
I need a regular expression that will match on all terms in a set
I need to match a string (any character or symbol other than space) with
I need to specify in a regular expression to match all positive and negative

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.