[:punct:] vs [[:punct:]]

Hi,

What is the difference between:

[:punct:]+

and

[[:punch:]]+

??

Thanks
Juan
uhm... what? Is this c++?
Last edited on
these are Regular expressions character classes (used in regex)

http://www.cplusplus.com/reference/regex/ECMAScript/#character_classes


I found this:
[abc[:digit:]] is a character class that matches a, b, c, or a digit.


So presumably one could do :

[abc[:punct:]] which would match punctuation as well as a b c.

So it looks like no difference between :

[:punct:] and [[:punct:]]

Hope that helps :+)
closed account (z05DSL3A)
There is a difference...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <regex>
#include <string>

using namespace std;

int main()
{
    string input;
    
    regex punct1("[:punct:]+");
    regex punct2("[[:punct:]]+");
    
    while(true)
    {
        cout<<"Give me punct!"<<endl;
        cin>>input;
        if(!cin) break;
        //Exit when the user inputs q
        if(input=="q")
            break;
        if(regex_match(input,punct1))
            cout<<"is in :punct:"<<endl;
        else
        {
            cout<<"Invalid input"<<endl;
        }
        if(regex_match(input,punct2))
            cout<<"is punct"<<endl;
        else
        {
            cout<<"Invalid input"<<endl;
        }
    }
}

Give me punct!
p
is in :punct:
Invalid input
Give me punct!
,
Invalid input
is punct
Give me punct!


So
[:punct:] = the set of characters ;punct:
[[:punct:]] = the set that includes the subset of punctuation characters.
Last edited on
Yes, I ran it and they are different...

I tested by inputing comma or period and that is NOT matched by [:punct:]+ but IS MATCHED by [[:punch:]]+

On the other hand, if input is :, then it is matched by both!!

I GOT IT!! Thanks

Topic archived. No new replies allowed.