File: pcrepp_Pcre.3

package info (click to toggle)
libpcre%2B%2B 0.9.5-6.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 2,032 kB
  • ctags: 194
  • sloc: sh: 6,870; cpp: 835; makefile: 41
file content (1216 lines) | stat: -rw-r--r-- 30,953 bytes parent folder | download | duplicates (5)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
.TH "pcrepp::Pcre" 3 "25 Aug 2004" "PCRE++" \" -*- nroff -*-
.ad l
.nh
.SH NAME
pcrepp::Pcre \- 
.SH SYNOPSIS
.br
.PP
\fC#include <pcre++.h>\fP
.PP
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBPcre\fP ()"
.br
.ti -1c
.RI "\fBPcre\fP (const std::string &expression)"
.br
.ti -1c
.RI "\fBPcre\fP (const std::string &expression, const std::string &flags)"
.br
.ti -1c
.RI "\fBPcre\fP (const std::string &expression, unsigned int flags)"
.br
.ti -1c
.RI "\fBPcre\fP (const Pcre &P)"
.br
.ti -1c
.RI "const Pcre & \fBoperator=\fP (const std::string &expression)"
.br
.ti -1c
.RI "const Pcre & \fBoperator=\fP (const Pcre &P)"
.br
.ti -1c
.RI "\fB~Pcre\fP ()"
.br
.ti -1c
.RI "bool \fBsearch\fP (const std::string &stuff)"
.br
.ti -1c
.RI "bool \fBsearch\fP (const std::string &stuff, int OffSet)"
.br
.ti -1c
.RI "std::vector< std::string > * \fBget_sub_strings\fP () const"
.br
.ti -1c
.RI "std::string \fBget_match\fP (int pos) const"
.br
.ti -1c
.RI "int \fBget_match_start\fP (int pos) const"
.br
.ti -1c
.RI "int \fBget_match_end\fP (int pos) const"
.br
.ti -1c
.RI "int \fBget_match_start\fP () const"
.br
.ti -1c
.RI "int \fBget_match_end\fP () const"
.br
.ti -1c
.RI "size_t \fBget_match_length\fP (int pos) const"
.br
.ti -1c
.RI "bool \fBmatched\fP () const"
.br
.ti -1c
.RI "int \fBmatches\fP () const"
.br
.ti -1c
.RI "std::vector< std::string > \fBsplit\fP (const std::string &piece)"
.br
.ti -1c
.RI "std::vector< std::string > \fBsplit\fP (const std::string &piece, int limit)"
.br
.ti -1c
.RI "std::vector< std::string > \fBsplit\fP (const std::string &piece, int limit, int start_offset)"
.br
.ti -1c
.RI "std::vector< std::string > \fBsplit\fP (const std::string &piece, int limit, int start_offset, int end_offset)"
.br
.ti -1c
.RI "std::vector< std::string > \fBsplit\fP (const std::string &piece, std::vector< int > positions)"
.br
.ti -1c
.RI "std::string \fBreplace\fP (const std::string &piece, const std::string &with)"
.br
.ti -1c
.RI "pcre * \fBget_pcre\fP ()"
.br
.ti -1c
.RI "pcre_extra * \fBget_pcre_extra\fP ()"
.br
.ti -1c
.RI "void \fBstudy\fP ()"
.br
.ti -1c
.RI "bool \fBsetlocale\fP (const char *locale)"
.br
.ti -1c
.RI "std::string \fBoperator[]\fP (int index)"
.br
.in -1c
.SH "Detailed Description"
.PP 
The \fBPcre\fP class is a wrapper around the PCRE library.
.PP
The library 'pcre++' defines a class named 'Pcre' which you can use to search in strings using reular expressions as well as getting matched sub strings. It does currently not support all features, which the underlying PCRE library provides, but the most important stuff is implemented.
.PP
Please study this example code to learn how to use this class: 
.PP
.nf
/*
 *
 *  This file  is part of the PCRE++ Class Library.
 *
 *  By  accessing  this software,  PCRE++, you  are  duly informed
 *  of and agree to be  bound  by the  conditions  described below
 *  in this notice:
 *
 *  This software product,  PCRE++,  is developed by Thomas Linden
 *  and  copyrighted (C) 2002  by  Thomas Linden,  with all rights 
 *  reserved.
 *
 *  There  is no charge for PCRE++ software.  You can redistribute
 *  it and/or modify it under the terms of the GNU  Lesser General
 *  Public License, which is incorporated by reference herein.
 *
 *  PCRE++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS,
 *  OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that
 *  the use of it will not infringe on any third party's intellec-
 *  tual property rights.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with PCRE++.  Copies can also be obtained from:
 *
 *    http://www.gnu.org/licenses/lgpl.txt
 *
 *  or by writing to:
 *
 *  Free Software Foundation, Inc.
 *  59 Temple Place, Suite 330
 *  Boston, MA 02111-1307
 *  USA
 *
 *  Or contact:
 *
 *   'Thomas Linden' <tom@daemon.de>
 *
 *
 */


/* you need to include the pcre++ header file */
#include '../libpcre++/pcre++.h'
#include <iostream>

using namespace std;
using namespace pcrepp;

/* A typedef for a vector of strings (as returned by split() )*/
typedef std::vector<std::string> Array;

/* A typedef for a vector iterator */
typedef std::vector<std::string>::iterator ArrayIterator;

void regex() {
    /*
     * define a string with a regular expression
     */
    string expression = '([a-z]*) ([0-9]+)';

    /*
     * this is the string in which we want to search
     */
    string stuff = 'hallo 11 robert';

    cout << '  searching in \'' << stuff << '\' for regex \''
         << expression << '\':' << endl;

    /*
     * Create a new Pcre object, search case-insensitive ('i')
     */
    Pcre reg(expression, 'i');
    
    /*
     * see if the expression matched
     */
    if(reg.search(stuff) == true) {

      /*
       * see if the expression generated any substrings
       */
      if(reg.matches() >= 1) {

        /*
         * print out the number of substrings
         */
        cout << '  generated ' << reg.matches() << ' substrings:' << endl;
          
        /*
         * iterate over the matched sub strings
         */
        for(int pos=0; pos < reg.matches(); pos++) {
          /* print out each substring */
          cout << '  substring ' << pos << ': ' << reg[pos];   // also possible: reg.get_match(pos);
          /* print out the start/end offset of the current substring
           * within the searched string(stuff)
           */
          cout << ' (start: ' << reg.get_match_start(pos) << ', end: '
               << reg.get_match_end(pos) << ')' << endl;
        }
      }
      else {
        /*
         * we had a match, but it generated no substrings, for whatever reason
         */
        cout << '   it matched, but there where no substrings.' << endl;
      }
    }
    else {
      /*
       * no match at all
       */
      cout << '   didn't match.' << endl;
    }
}



void replace() {
    /*
     * Sample of replace() usage
     */
    string orig = 'Hans ist 22 Jahre alt. Er ist 8 Jahre lter als Fred.';
    cout << '   orig: ' << orig << endl;

    /*
     * define a regex for digits (character class)
     */
    Pcre p(' ([0-9]+) ');

    /*
     * replace the 1st occurence of [0-9]+ with 'zweiundzwanzig'
     */
    string n = p.replace(orig, ' zweiundzwanzig($1) ');

    /*
     * prints out: 'Hans ist zweiundzwanzig Jahre alt. Er ist 8 Jahre lter
     * als Fred.'
     */
    cout << '   new: ' << n << endl; 
}


void replace_multi() {
  /*
   * Sample of replace() usage with multiple substrings
   */
  string orig = ' 08:23 ';
  cout << '   orig: ' << orig << endl;
  
  /*
   * create regex which, if it matches, creates 3 substrings
   */
  Pcre reg(' ([0-9]+)(:)([0-9]+) ', 'sig');

  /*
   * remove $2 (':')
   * re-use $1 ('08') and $3 ('23') in the replace string
   */
  string n  = reg.replace(orig, '$1 Stunden und $3 Minuten');

  /*
   * prints the result: '08 Stunden und 23 Minuten'
   */
  cout << '   new:  ' << n  << endl;
}


void normalize() {
  /*
   * another sample to check if normalizing using replace() works
   */
  string orig = 'Heute   ist ein  schoener  Tag        gell?';
  cout << '   orig: ' << orig << endl;

  /*
   * create regex for normalizing whitespace
   */
  Pcre reg('[\\s]+', 'gs');

  /*
   * do the normalizing process
   */
  string n = reg.replace(orig, ' ');

  /*
   * prints the result, should be: 'Heute ist ein schoener Tag , gell?'
   */
  cout << '   new:  ' << n  << endl;
}


void split() {
  /*
   * Sample of split() usage
   */
      string sp_orig = 'was21willst2387461du3alter!';
      cout << '   orig: ' << sp_orig << endl;

      /*
       * define a regex for digits (character class)
       */
      string delimiter = '[0-9]+';

      /*
       * new Pcre object, match globally ('g' flag)
       */
      Pcre S(delimiter, 'g');

      /*
       * split 'was21willst2387461du3alter!' by digits
       */
      Array splitted = S.split(sp_orig);
      
      /*
       * iterate over the resulting list
       */
      cout << '   splitted: ';
      for(ArrayIterator A = splitted.begin(); A != splitted.end(); ++A)
        cout << *A << ' ';
      cout << endl;
}


void ex() {
  /*
   * Pcre::exception Test
   */
  
  /*
   * this will generate only one substring, 'This'
   */
  Pcre ex('([a-z]+)', 'i');
  if(ex.search('This is a test.')) {
    cout << '  trying to access a non-existing substring:' << endl;
    cout << '  substring 2: ' << ex.get_match(1) << endl; 
  }
}


void mycopy() {
  /*
   * Sample use of copy contsructor and operator=
   */
    cout << '  initializing reg1(([a-z]+?)' << endl;
    Pcre reg1('^([a-z]+?)');

    /*
     * create an empty Pcre objects
     */
    Pcre reg2;
    
    /*
     * copy reg1 to reg2 (operator=)
     */
    cout << '  copying reg1 to new Pcre object reg2' << endl;
    reg2 = reg1;

    /*
     * using the copy constructor to initialize the 3rd object
     */
    cout << '  creating a new Pcre object reg3 from reg2' << endl;
    Pcre reg3(reg2);

    /*
     * doing regular stuff on reg3
     */
    if(reg3.search('anton'))
      cout << '  string 'anton' matched using reg3 object' << endl;
}

void multisearch() {
  Pcre reg('([^\\n]+\\n)');
  string str = '\nline1\nline2\nline3\n';
  size_t pos = 0;

  while (pos <= str.length()) {
    if( reg.search(str, pos)) {
      pos = reg.get_match_end(0);
      cout << '   pos: ' << pos << ' match: ' << reg.get_match(0);
    }
    else
      break;
  }
}

int main() {
  /* 
   * the Pcre class throws errors via exceptions
   */
  try {
    cout << endl << 'SEARCH() sample:' << endl;
    regex();

    cout << endl << 'REPLACE() sample:' << endl;
    replace();

    cout << endl << 'Multiple REPLACE() sample:' << endl;
    replace_multi();

    cout << endl << 'Normalizing REPLACE() sample:' << endl;
    normalize();

    cout << endl << 'SPLIT() sample:' << endl;
    split();

    cout << endl << 'COPY+Operator sample:' << endl;
    mycopy();

    cout << endl << 'Multi line search test:' << endl;
    multisearch();

    cout << endl << 'Pcre::exception test:' << endl;
    ex();

    exit(0);
  }
  catch (Pcre::exception &E) {
    /*
     * the Pcre class has thrown an exception
     */
    cerr << 'Pcre++ error: ' << E.what() << endl;
    exit(-1);
  }
  exit(0);
}
  

.PP
.PP
Compile your programs which use the prce++ class using the following command line: 
.PP
.nf

   g++ -c yourcode.o `pcre-config --cflags` `pcre++-config --cflags`
   g++ yourcode.o `pcre-config --libs` `pcre++-config --libs` -o yourprogram
 

.PP
.PP
If you want to learn more about regular expressions which can be used with pcre++, then please read the following documentation: \fCperlre - Perl regular expressions\fP
.PP
The pcre library itself does also contain some usefull documentation, which maybe interesting for you: \fCPCRE manual page\fP 
.PP
Definition at line 99 of file pcre++.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "Pcre::Pcre ()"
.PP
Empty Constructor. Create a new empty \fBPcre\fP object. This is the simplest constructor available, you might consider one of the other constructors as a better solution. You need to initialize thie \fBPcre\fP object, if you use the empty constructor. You can use one of the two available operator= operators to assign it an expression or a \fBPcre\fP copy.
.PP
\fBReturns:\fP
.RS 4
A new empty \fBPcre\fP object 
.RE
.PP
Definition at line 107 of file pcre++.cc.
.SS "Pcre::Pcre (const std::string & expression)"
.PP
Constructor. Compile the given pattern. An \fBPcre\fP object created this way can be used multiple times to do searches.
.PP
\fBParameters:\fP
.RS 4
\fIexpression\fP a string, which must be a valid perl regular expression. 
.RE
.PP
\fBReturns:\fP
.RS 4
A new \fBPcre\fP object, which holds te compiled pattern. 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBPcre(const std::string& expression, const std::string& flags)\fP 
.PP
\fBPcre(const std::string& expression, unsigned int flags)\fP 
.RE
.PP
Definition at line 50 of file pcre++.cc.
.SS "Pcre::Pcre (const std::string & expression, const std::string & flags)"
.PP
Constructor. Compile the given pattern. An \fBPcre\fP object created this way can be used multiple times to do searches.
.PP
\fBParameters:\fP
.RS 4
\fIexpression\fP a string, which must be a valid perl regular expression. 
.br
\fIflags\fP can be one or more of the following letters:
.RE
.PP
.IP "\(bu" 2
\fBi\fP Search case insensitive.
.PP
.PP
.IP "\(bu" 2
\fBm\fP Match on multiple lines, thus ^ and $ are interpreted as the start and end of the entire string, not of a single line.
.PP
.PP
.IP "\(bu" 2
\fBs\fP A dot in an expression matches newlines too(which is normally not the case).
.PP
.PP
.IP "\(bu" 2
\fBx\fP Whitespace characters will be ignored (except within character classes or if escaped).
.PP
.PP
.IP "\(bu" 2
\fBg\fP Match multiple times. This flags affects only the behavior of the \fBreplace(const std::string& piece, const std::string& with)\fP method.
.PP
.PP
\fBReturns:\fP
.RS 4
A new \fBPcre\fP object, which holds te compiled pattern. 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBPcre(const std::string& expression)\fP 
.PP
\fBPcre(const std::string& expression, unsigned int flags)\fP 
.RE
.PP
Definition at line 59 of file pcre++.cc.
.SS "Pcre::Pcre (const std::string & expression, unsigned int flags)"
.PP
Constructor. Compile the given pattern. An \fBPcre\fP object created this way can be used multiple times to do searches.
.PP
\fBParameters:\fP
.RS 4
\fIexpression\fP a string, which must be a valid perl regular expression. 
.br
\fIflags\fP option bits can be one or more of the following bits:
.RE
.PP
.IP "\(bu" 2
PCRE_ANCHORED anchored pattern.
.IP "\(bu" 2
PCRE_CASELESS case insensitive search.
.IP "\(bu" 2
PCRE_DOLLAR_ENDONLY dollar sign matches only at end.
.IP "\(bu" 2
PCRE_DOTALL newline is contained in .
.IP "\(bu" 2
PCRE_EXTENDED whitespace characters will be ignored.
.IP "\(bu" 2
PCRE_EXTRA use perl incompatible pcre extensions.
.IP "\(bu" 2
PCRE_MULTILINE match on multiple lines.
.IP "\(bu" 2
PCRE_NO_AUTO_CAPTURE disable the use of numbered capturing parentheses in the pattern.
.IP "\(bu" 2
PCRE_UNGREEDY qunatifiers behave not greedy by default.
.IP "\(bu" 2
PCRE_UTF8 use utf8 support.
.IP "\(bu" 2
PCRE_GLOBAL (PCRE++ internal flag) match multiple times used only in the \fBreplace(const std::string& piece, const std::string& with)\fP method.
.PP
.PP
\fBReturns:\fP
.RS 4
A new \fBPcre\fP object, which holds te compiled pattern. 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBPcre(const std::string& expression)\fP 
.PP
\fBPcre(const std::string& expression, const std::string& flags)\fP 
.PP
pcreapi(3) manpage 
.RE
.PP
Definition at line 80 of file pcre++.cc.
.PP
References PCRE_GLOBAL.
.SS "Pcre::Pcre (const Pcre & P)"
.PP
Copy Constructor Creates a new \fBPcre\fP object of an existing one. 
.PP
\fBParameters:\fP
.RS 4
\fIP\fP an existing \fBPcre\fP object. 
.RE
.PP
\fBReturns:\fP
.RS 4
A new \fBPcre\fP object, which holds te compiled pattern. 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBPcre(const std::string& expression)\fP 
.PP
\fBPcre(const std::string& expression, const std::string& flags)\fP 
.RE
.PP
Definition at line 97 of file pcre++.cc.
.PP
References _expression, _flags, _have_paren, case_t, and global_t.
.SS "Pcre::~Pcre ()"
.PP
Destructor. The desturcor will automatically invoked if the object is no more used. It frees all the memory allocated by pcre++. Definition at line 120 of file pcre++.cc.
.SH "Member Function Documentation"
.PP 
.SS "string Pcre::get_match (int pos) const"
.PP
Get a substring at a known position. This method throws an out-of-range exception if the given position is invalid. 
.PP
\fBParameters:\fP
.RS 4
\fIpos\fP the position of the substring to return. Identical to perl's $1..$n. 
.RE
.PP
\fBReturns:\fP
.RS 4
the substring at the given position.
.RE
.PP
Example: 
.PP
.nf

 
 std::string mysub = regex.get_match(1); 
 
 

.PP
Get the first substring that matched the expression in the 'regex' object. 
.PP
Definition at line 60 of file get.cc.
.PP
Referenced by operator[]().
.SS "int Pcre::get_match_end () const"
.PP
Get the end position of the entire match within the searched string. This method returns the character position of the last character of the entire match within the searched string. 
.PP
\fBReturns:\fP
.RS 4
the integer character position of the last character of the entire match.
.RE
.PP
Example: 
.PP
.nf


 Pcre regex('([0-9]+)\s([a-z]+)');     // search for the date(makes 2 substrings
 regex.search('The 11th september.');  // do the search on this string
 int pos = regex.get_match_end();      // returns 17, because '11th september', which is
                                           // the entire match, ends at the
                                       // 17th character inside the search string.

 

.PP
\fBSee also:\fP
.RS 4
int \fBget_match_start()\fP 
.PP
int get_match_start(int pos) 
.PP
int get_match_end(int pos) 
.RE
.PP

.PP
Definition at line 77 of file get.cc.
.PP
Referenced by replace().
.SS "int Pcre::get_match_end (int pos) const"
.PP
Get the end position of a substring within the searched string. This method returns the character position of the last character of a substring withing the searched string. 
.PP
\fBParameters:\fP
.RS 4
\fIpos\fP the position of the substring. Identical to perl's $1..$n. 
.RE
.PP
\fBReturns:\fP
.RS 4
the integer character position of the last character of a substring. Positions are starting at 0.
.RE
.PP
Example: 
.PP
.nf


 Pcre regex('([0-9]+)');               // search for numerical characters
 regex.search('The 11th september.');  // do the search on this string
 std::string day = regex.get_match(1);      // returns '11'
 int pos = regex.get_match_end(1);     // returns 5, because '11' ends at the
                                       // 5th character inside the search string.

 

.PP
\fBSee also:\fP
.RS 4
int get_match_start(int pos) 
.PP
int \fBget_match_start()\fP 
.PP
int \fBget_match_end()\fP 
.RE
.PP

.PP
Definition at line 96 of file get.cc.
.SS "size_t Pcre::get_match_length (int pos) const"
.PP
Get the length of a substring at a known position. This method throws an out-of-range exception if the given position is invalid. 
.PP
\fBParameters:\fP
.RS 4
\fIpos\fP the position of the substring-length to return. Identical to perl's $1..$n. 
.RE
.PP
\fBReturns:\fP
.RS 4
the length substring at the given position. 
.RE
.PP
Definition at line 110 of file get.cc.
.SS "int Pcre::get_match_start () const"
.PP
Get the start position of the entire match within the searched string. This method returns the character position of the first character of the entire match within the searched string. 
.PP
\fBReturns:\fP
.RS 4
the integer character position of the first character of the entire match.
.RE
.PP
Example: 
.PP
.nf


 Pcre regex('([0-9]+)\s([a-z]+)');     // search for the date(makes 2 substrings
 regex.search('The 11th september.');  // do the search on this string
 int pos = regex.get_match_start();    // returns 4, because '11th september' begins at the
                                       // 4th character inside the search string.

 

.PP
\fBSee also:\fP
.RS 4
int get_match_start(int pos) 
.PP
int get_match_end(int pos) 
.PP
int \fBget_match_end()\fP 
.RE
.PP

.PP
Definition at line 70 of file get.cc.
.PP
Referenced by replace().
.SS "int Pcre::get_match_start (int pos) const"
.PP
Get the start position of a substring within the searched string. This method returns the character position of the first character of a substring withing the searched string. 
.PP
\fBParameters:\fP
.RS 4
\fIpos\fP the position of the substring. Identical to perl's $1..$n. 
.RE
.PP
\fBReturns:\fP
.RS 4
the integer character position of the first character of a substring. Positions are starting at 0.
.RE
.PP
Example: 
.PP
.nf

 
 Pcre regex('([0-9]+)');               // search for numerical characters
 regex.search('The 11th september.');  // do the search on this string
 std::string day = regex.get_match(1);      // returns '11'
 int pos = regex.get_match_start(1);   // returns 4, because '11' begins at the
                                       // 4th character inside the search string.

 

.PP
\fBSee also:\fP
.RS 4
int get_match_end(int pos) 
.PP
int \fBget_match_end()\fP 
.PP
int \fBget_match_start()\fP 
.RE
.PP

.PP
Definition at line 84 of file get.cc.
.SS "pcre * Pcre::get_pcre ()"
.PP
Return pointer to underlying pcre object. The pcre object allows you to access the pcre API directly. E.g. if your are using pcre version 4.x and want to use the new functionality which is currently not supported by pcre++. An example would be: pcre_fullinfo(), pcre_study() or the callout functionality.
.PP
\fBReturns:\fP
.RS 4
'pcre*' pointer to pcre object. 
.RE
.PP
\fBSee also:\fP
.RS 4
man pcre 
.PP
pcre_extra* \fBget_pcre_extra()\fP 
.RE
.PP
Definition at line 195 of file pcre++.cc.
.SS "pcre_extra * Pcre::get_pcre_extra ()"
.PP
Return pointer to underlying pcre_extra structure. The returned pcre_extra structure can be used in conjunction with the pcre* object returned by pcre().
.PP
\fBReturns:\fP
.RS 4
'pcre_extra*' pointer to pcre_extra structure. 
.RE
.PP
\fBSee also:\fP
.RS 4
pcre* \fBget_pcre()\fP 
.RE
.PP
Definition at line 199 of file pcre++.cc.
.SS "vector< string > * Pcre::get_sub_strings () const"
.PP
Return a vector of substrings, if any. 
.PP
\fBReturns:\fP
.RS 4
a pointer to an std::vector<std::string>, which may be NULL, if no substrings has been found. 
.RE
.PP
\fBSee also:\fP
.RS 4
std::vector<std::string> 
.RE
.PP
Definition at line 53 of file get.cc.
.SS "bool pcrepp::Pcre::matched () const\fC [inline]\fP"
.PP
Test if a search was successfull. This method must be invoked \fBafter\fP calling \fBsearch()\fP. 
.PP
\fBReturns:\fP
.RS 4
boolean \fBtrue\fP if the search was successfull at all, or \fBfalse\fP if not. 
.RE
.PP
Definition at line 444 of file pcre++.h.
.PP
Referenced by replace().
.SS "int pcrepp::Pcre::matches () const\fC [inline]\fP"
.PP
Get the number of substrings generated by pcre++. 
.PP
\fBReturns:\fP
.RS 4
the number of substrings generated by pcre++. 
.RE
.PP
Definition at line 449 of file pcre++.h.
.PP
Referenced by replace().
.SS "const Pcre & Pcre::operator= (const Pcre & P)"
.PP
Operator =. 
.PP
\fBParameters:\fP
.RS 4
\fI&P\fP an \fBPcre\fP object 
.RE
.PP
\fBReturns:\fP
.RS 4
a new \fBPcre\fP object
.RE
.PP
Example:
.PP
.PP
.nf

 Pcre reg1('^[a-z]+?');
 Pcre reg2;
 reg2 = reg1;
 
.PP

.PP
Definition at line 153 of file pcre++.cc.
.PP
References _expression, _flags, case_t, and global_t.
.SS "const Pcre & Pcre::operator= (const std::string & expression)"
.PP
Operator =. 
.PP
\fBParameters:\fP
.RS 4
\fIexpression\fP a valid regular expression. 
.RE
.PP
\fBReturns:\fP
.RS 4
a new \fBPcre\fP object.
.RE
.PP
Example:
.PP
.PP
.nf

 Pcre regex = '(A+?)';
 
.PP

.PP
Definition at line 142 of file pcre++.cc.
.SS "std::string pcrepp::Pcre::operator[] (int index)\fC [inline]\fP"
.PP
Return substring of a match at a known possition using the array notation. This method throws an out-of-range exception if the given position is invalid. 
.PP
\fBParameters:\fP
.RS 4
\fIindex\fP the position of the substring to return. Identical to perl's $1..$n. 
.RE
.PP
\fBReturns:\fP
.RS 4
the substring at the given position.
.RE
.PP
Example: 
.PP
.nf

 
 std::string mysub = regex[1]; 
 
 

.PP
Get the first substring that matched the expression in the 'regex' object.
.PP
\fBSee also:\fP
.RS 4
std::string get_match(int pos) 
.RE
.PP

.PP
Definition at line 594 of file pcre++.h.
.PP
References get_match().
.SS "string Pcre::replace (const std::string & piece, const std::string & with)"
.PP
Replace parts of a string using regular expressions. This method is the counterpart of the perl s/// operator. It replaces the substrings which matched the given regular expression (given to the constructor) with the supplied string.
.PP
\fBParameters:\fP
.RS 4
\fIpiece\fP the string in which you want to search and replace. 
.br
\fIwith\fP the string which you want to place on the positions which match the expression (given to the constructor). 
.RE
.PP
Definition at line 51 of file replace.cc.
.PP
References __pcredebug, get_match_end(), get_match_start(), matched(), matches(), and search().
.SS "bool Pcre::search (const std::string & stuff, int OffSet)"
.PP
Do a search on the given string beginning at the given offset. This method does the actual search on the given string. 
.PP
\fBParameters:\fP
.RS 4
\fIstuff\fP the string in which you want to search for something. 
.br
\fIOffSet\fP the offset where to start the search. 
.RE
.PP
\fBReturns:\fP
.RS 4
boolean \fBtrue\fP if the regular expression matched. \fBfalse\fP if not. 
.RE
.PP
\fBSee also:\fP
.RS 4
bool \fBsearch(const std::string& stuff)\fP 
.RE
.PP
Definition at line 83 of file search.cc.
.SS "bool Pcre::search (const std::string & stuff)"
.PP
Do a search on the given string. This method does the actual search on the given string. 
.PP
\fBParameters:\fP
.RS 4
\fIstuff\fP the string in which you want to search for something. 
.RE
.PP
\fBReturns:\fP
.RS 4
boolean \fBtrue\fP if the regular expression matched. \fBfalse\fP if not. 
.RE
.PP
\fBSee also:\fP
.RS 4
bool \fBsearch(const std::string& stuff, int OffSet)\fP 
.RE
.PP
Definition at line 87 of file search.cc.
.PP
Referenced by replace().
.SS "bool Pcre::setlocale (const char * locale)"
.PP
Sets locale for all character operations Returns false if locale can't be set. Otherwise returns true 
.PP
\fBParameters:\fP
.RS 4
\fIlocale\fP locale alias name you want to use. 
.RE
.PP
\fBReturns:\fP
.RS 4
true if setting locale were successful
.RE
.PP
\fBSee also:\fP
.RS 4
locale(1) 
.RE
.PP
Definition at line 220 of file pcre++.cc.
.SS "vector< string > Pcre::split (const std::string & piece, std::vector< int > positions)"
.PP
split a string into pieces This method will split the given string into a vector of strings using the compiled expression (given to the constructor).
.PP
\fBParameters:\fP
.RS 4
\fIpiece\fP The string you want to split into it's parts. 
.br
\fIpositions\fP a std::vector<int> of positions, which the returned vector should contain. 
.RE
.PP
\fBReturns:\fP
.RS 4
an vector of strings 
.RE
.PP
\fBSee also:\fP
.RS 4
std::vector<std::string> \fBsplit(const std::string& piece)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit, int start_offset)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit, int start_offset)\fP 
.PP
std::vector<std::string> 
.RE
.PP
Definition at line 151 of file split.cc.
.SS "vector< string > Pcre::split (const std::string & piece, int limit, int start_offset, int end_offset)"
.PP
split a string into pieces This method will split the given string into a vector of strings using the compiled expression (given to the constructor).
.PP
\fBParameters:\fP
.RS 4
\fIpiece\fP The string you want to split into it's parts. 
.br
\fIlimit\fP the maximum number of elements you want to get back from \fBsplit()\fP. 
.br
\fIstart_offset\fP at which substring the returned vector should start. 
.br
\fIend_offset\fP at which substring the returned vector should end. 
.RE
.PP
\fBReturns:\fP
.RS 4
an vector of strings 
.RE
.PP
\fBSee also:\fP
.RS 4
std::vector<std::string> \fBsplit(const std::string& piece)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit, int start_offset)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, std::vector<int> positions)\fP 
.PP
std::vector<std::string> 
.RE
.PP
Definition at line 147 of file split.cc.
.SS "vector< string > Pcre::split (const std::string & piece, int limit, int start_offset)"
.PP
split a string into pieces This method will split the given string into a vector of strings using the compiled expression (given to the constructor).
.PP
\fBParameters:\fP
.RS 4
\fIpiece\fP The string you want to split into it's parts. 
.br
\fIlimit\fP the maximum number of elements you want to get back from \fBsplit()\fP. 
.br
\fIstart_offset\fP at which substring the returned vector should start. 
.RE
.PP
\fBReturns:\fP
.RS 4
an vector of strings 
.RE
.PP
\fBSee also:\fP
.RS 4
std::vector<std::string> 
.PP
std::vector<std::string> \fBsplit(const std::string& piece)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit, int start_offset, int end_offset)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, std::vector<int> positions)\fP 
.RE
.PP
Definition at line 143 of file split.cc.
.SS "vector< string > Pcre::split (const std::string & piece, int limit)"
.PP
split a string into pieces This method will split the given string into a vector of strings using the compiled expression (given to the constructor).
.PP
\fBParameters:\fP
.RS 4
\fIpiece\fP The string you want to split into it's parts. 
.br
\fIlimit\fP the maximum number of elements you want to get back from \fBsplit()\fP. 
.RE
.PP
\fBReturns:\fP
.RS 4
an vector of strings 
.RE
.PP
\fBSee also:\fP
.RS 4
std::vector<std::string> 
.PP
std::vector<std::string> \fBsplit(const std::string& piece)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit, int start_offset)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit, int start_offset, int end_offset)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, std::vector<int> positions)\fP 
.RE
.PP
Definition at line 139 of file split.cc.
.SS "vector< string > Pcre::split (const std::string & piece)"
.PP
split a string into pieces This method will split the given string into a vector of strings using the compiled expression (given to the constructor).
.PP
\fBParameters:\fP
.RS 4
\fIpiece\fP The string you want to split into it's parts. 
.RE
.PP
\fBReturns:\fP
.RS 4
an vector of strings 
.RE
.PP
\fBSee also:\fP
.RS 4
std::vector<std::string> 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit, int start_offset)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, int limit, int start_offset, int end_offset)\fP 
.PP
std::vector<std::string> \fBsplit(const std::string& piece, std::vector<int> positions)\fP 
.RE
.PP
Definition at line 135 of file split.cc.
.SS "void Pcre::study ()"
.PP
Analyze pattern for speeding up the matching process. When a pattern is going to be used several times, it is worth spending more time analyzing it in order to speed up the time taken for matching.
.PP
An excpetion will be thrown if analyzing the pattern failed. Definition at line 210 of file pcre++.cc.

.SH "Author"
.PP 
Generated automatically by Doxygen for PCRE++ from the source code.