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

  • Home
  • SEARCH
  • 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 4561540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:05:20+00:00 2026-05-21T18:05:20+00:00

I use the following regular expression: NSString *reg1 = @/[$|§|%|&|{|}|’|`|´|^|°|~]/i; NSPredicate *messageTest = [NSPredicate

  • 0

I use the following regular expression:

NSString *reg1 = @"/[$|§|%|&|{|}|'|`|´|^|°|~]/i";

NSPredicate *messageTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",
                           reg1];

And I test if the string matches this regex:

if([messageTest evaluateWithObject:message] == NO){
        messageValid = NO;
        NSLog(@"message invalid");
}

So if the text contains any of the characters that are specified in the regular expression the text is invalid.

This regex worked for me in javascript. However in objective-c I get always NO regardless of what characters are in the string.

Where is the problem?

  • 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-21T18:05:20+00:00Added an answer on May 21, 2026 at 6:05 pm

    There are essentially two problems with your code. Firstly, your regular expression

    NSString *reg1 = @"/[$|§|%|&|{|}|'|`|´|^|°|~]/i";
    

    is wrong:

    • ICU regular expressions do not use /pattern/modifier. Also, why would you specify a case-insensitive match for that character set?
    • ICU regular expressions need the following characters to be quoted: $ { } ^
    • As ridgerunner mentioned, do not use | to separate characters in a character class.

    The ICU regular expression you want is

    [\$§%&\{\}'`´\^°~]
    

    Try this in your program:

    NSString *reg1 = @"[\\$§%&\\{\\}'`´\\^°~]";
    

    (note that the \ character is represented as \\ in an Objective-C string.)

    Secondly, you’re testing

    if([messageTest evaluateWithObject:message] == NO)
    

    to check whether a message is invalid. But -evaluateWithObject: returning NO means that there wasn’t a match, hence the string doesn’t contain any of those characters, hence the string is valid. You need to change that to its opposite, namely:

    if([messageTest evaluateWithObject:message])
    

    which means that there was a match, hence the string contain at least one of those characters, hence the string isn’t valid.

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

Sidebar

Related Questions

I am trying to use the following regular expression to check whether a string
My string is in a foreign language. I use the following regular expression: $str
I use the following regular expression to validate a comma separated list of values.
I want to use the following regular expression which is written within a C#
I have an issue regarding the use of the following regular expression: private Regex
Having the following regular expression: ([a-z])([0-9])\1 It matches a5a , is there any way
I have the following regular expression: ([0-9]+),'(.)':([0-9]+),(L|R|'.') It matches this just fine: 1,'a':1,R However,
I need to use the following regular expression to validate some Asian characters $regexp
Currently, I use the following regular expression for the user to enter a password
I want to use a regular expression that would do the following thing (

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.