File: Manipulating-Strings.html

package info (click to toggle)
octave 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 124,192 kB
  • sloc: cpp: 322,665; ansic: 68,088; fortran: 20,980; objc: 8,121; sh: 7,719; yacc: 4,266; lex: 4,123; perl: 1,530; java: 1,366; awk: 1,257; makefile: 424; xml: 147
file content (1209 lines) | stat: -rw-r--r-- 46,851 bytes parent folder | download
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Manipulating Strings (GNU Octave (version 6.2.0))</title>

<meta name="description" content="Manipulating Strings (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Manipulating Strings (GNU Octave (version 6.2.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Strings.html" rel="up" title="Strings">
<link href="String-Conversions.html" rel="next" title="String Conversions">
<link href="Comparing-Strings.html" rel="prev" title="Comparing Strings">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<span id="Manipulating-Strings"></span><div class="header">
<p>
Next: <a href="String-Conversions.html" accesskey="n" rel="next">String Conversions</a>, Previous: <a href="Comparing-Strings.html" accesskey="p" rel="prev">Comparing Strings</a>, Up: <a href="Strings.html" accesskey="u" rel="up">Strings</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Manipulating-Strings-1"></span><h3 class="section">5.5 Manipulating Strings</h3>

<p>Octave supports a wide range of functions for manipulating strings.
Since a string is just a matrix, simple manipulations can be accomplished
using standard operators.  The following example shows how to replace
all blank characters with underscores.
</p>
<div class="example">
<pre class="example">quote = ...
  &quot;First things first, but not necessarily in that order&quot;;
quote( quote == &quot; &quot; ) = &quot;_&quot;
&rArr; quote =
    First_things_first,_but_not_necessarily_in_that_order
</pre></div>

<p>For more complex manipulations, such as searching, replacing, and
general regular expressions, the following functions come with Octave.
</p>
<span id="XREFdeblank"></span><dl>
<dt id="index-deblank">: <em></em> <strong>deblank</strong> <em>(<var>s</var>)</em></dt>
<dd><p>Remove trailing whitespace and nulls from <var>s</var>.
</p>
<p>If <var>s</var> is a matrix, <var>deblank</var> trims each row to the length of
longest string.  If <var>s</var> is a cell array of strings, operate
recursively on each string element.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">deblank (&quot;    abc  &quot;)
     &rArr;  &quot;    abc&quot;

deblank ([&quot; abc   &quot;; &quot;   def   &quot;])
     &rArr;  [&quot; abc  &quot; ; &quot;   def&quot;]
</pre></div>

<p><strong>See also:</strong> <a href="#XREFstrtrim">strtrim</a>.
</p></dd></dl>


<span id="XREFstrtrim"></span><dl>
<dt id="index-strtrim">: <em></em> <strong>strtrim</strong> <em>(<var>s</var>)</em></dt>
<dd><p>Remove leading and trailing whitespace from <var>s</var>.
</p>
<p>If <var>s</var> is a matrix, <var>strtrim</var> trims each row to the length of
longest string.  If <var>s</var> is a cell array of strings, operate recursively
on each string element.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">strtrim (&quot;    abc  &quot;)
     &rArr;  &quot;abc&quot;

strtrim ([&quot; abc   &quot;; &quot;   def   &quot;])
     &rArr;  [&quot;abc  &quot;  ; &quot;  def&quot;]
</pre></div>

<p><strong>See also:</strong> <a href="#XREFdeblank">deblank</a>.
</p></dd></dl>


<span id="XREFstrtrunc"></span><dl>
<dt id="index-strtrunc">: <em></em> <strong>strtrunc</strong> <em>(<var>s</var>, <var>n</var>)</em></dt>
<dd><p>Truncate the character string <var>s</var> to length <var>n</var>.
</p>
<p>If <var>s</var> is a character matrix, then the number of columns is adjusted.
</p>
<p>If <var>s</var> is a cell array of strings, then the operation is performed
on each cell element and the new cell array is returned.
</p></dd></dl>


<span id="XREFfindstr"></span><dl>
<dt id="index-findstr">: <em></em> <strong>findstr</strong> <em>(<var>s</var>, <var>t</var>)</em></dt>
<dt id="index-findstr-1">: <em></em> <strong>findstr</strong> <em>(<var>s</var>, <var>t</var>, <var>overlap</var>)</em></dt>
<dd>
<p>This function is obsolete.  Use <code>strfind</code> instead.
</p>
<p>Return the vector of all positions in the longer of the two strings <var>s</var>
and <var>t</var> where an occurrence of the shorter of the two starts.
</p>
<p>If the optional argument <var>overlap</var> is true (default), the returned
vector can include overlapping positions.  For example:
</p>
<div class="example">
<pre class="example">findstr (&quot;ababab&quot;, &quot;a&quot;)
     &rArr; [1, 3, 5];
findstr (&quot;abababa&quot;, &quot;aba&quot;, 0)
     &rArr; [1, 5]
</pre></div>

<p><strong>Caution:</strong> <code>findstr</code> is obsolete.  Use <code>strfind</code> in all new
code.
</p>
<p><strong>See also:</strong> <a href="#XREFstrfind">strfind</a>, <a href="#XREFstrmatch">strmatch</a>, <a href="Comparing-Strings.html#XREFstrcmp">strcmp</a>, <a href="Comparing-Strings.html#XREFstrncmp">strncmp</a>, <a href="Comparing-Strings.html#XREFstrcmpi">strcmpi</a>, <a href="Comparing-Strings.html#XREFstrncmpi">strncmpi</a>, <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>


<span id="XREFstrchr"></span><dl>
<dt id="index-strchr">: <em><var>idx</var> =</em> <strong>strchr</strong> <em>(<var>str</var>, <var>chars</var>)</em></dt>
<dt id="index-strchr-1">: <em><var>idx</var> =</em> <strong>strchr</strong> <em>(<var>str</var>, <var>chars</var>, <var>n</var>)</em></dt>
<dt id="index-strchr-2">: <em><var>idx</var> =</em> <strong>strchr</strong> <em>(<var>str</var>, <var>chars</var>, <var>n</var>, <var>direction</var>)</em></dt>
<dt id="index-strchr-3">: <em>[<var>i</var>, <var>j</var>] =</em> <strong>strchr</strong> <em>(&hellip;)</em></dt>
<dd><p>Search through the string <var>str</var> for occurrences of characters from the
set <var>chars</var>.
</p>
<p>The return value(s), as well as the <var>n</var> and <var>direction</var> arguments
behave identically as in <code>find</code>.
</p>
<p>This will be faster than using <code>regexp</code> in most cases.
</p>

<p><strong>See also:</strong> <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>


<span id="XREFindex"></span><dl>
<dt id="index-index">: <em></em> <strong>index</strong> <em>(<var>s</var>, <var>t</var>)</em></dt>
<dt id="index-index-1">: <em></em> <strong>index</strong> <em>(<var>s</var>, <var>t</var>, <var>direction</var>)</em></dt>
<dd><p>Return the position of the first occurrence of the string <var>t</var> in the
string <var>s</var>, or 0 if no occurrence is found.
</p>
<p><var>s</var> may also be a string array or cell array of strings.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">index (&quot;Teststring&quot;, &quot;t&quot;)
    &rArr; 4
</pre></div>

<p>If <var>direction</var> is <code>&quot;first&quot;</code>, return the first element found.
If <var>direction</var> is <code>&quot;last&quot;</code>, return the last element found.
</p>

<p><strong>See also:</strong> <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>, <a href="#XREFrindex">rindex</a>.
</p></dd></dl>


<span id="XREFrindex"></span><dl>
<dt id="index-rindex">: <em></em> <strong>rindex</strong> <em>(<var>s</var>, <var>t</var>)</em></dt>
<dd><p>Return the position of the last occurrence of the character string
<var>t</var> in the character string <var>s</var>, or 0 if no occurrence is
found.
</p>
<p><var>s</var> may also be a string array or cell array of strings.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">rindex (&quot;Teststring&quot;, &quot;t&quot;)
     &rArr; 6
</pre></div>

<p>The <code>rindex</code> function is equivalent to <code>index</code> with
<var>direction</var> set to <code>&quot;last&quot;</code>.
</p>

<p><strong>See also:</strong> <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>, <a href="#XREFindex">index</a>.
</p></dd></dl>


<span id="XREFstrfind"></span><dl>
<dt id="index-strfind">: <em><var>idx</var> =</em> <strong>strfind</strong> <em>(<var>str</var>, <var>pattern</var>)</em></dt>
<dt id="index-strfind-1">: <em><var>idx</var> =</em> <strong>strfind</strong> <em>(<var>cellstr</var>, <var>pattern</var>)</em></dt>
<dt id="index-strfind-2">: <em><var>idx</var> =</em> <strong>strfind</strong> <em>(&hellip;, &quot;overlaps&quot;, <var>val</var>)</em></dt>
<dt id="index-strfind-3">: <em><var>idx</var> =</em> <strong>strfind</strong> <em>(&hellip;, &quot;forcecelloutput&quot;, <var>val</var>)</em></dt>
<dd><p>Search for <var>pattern</var> in the string <var>str</var> and return the starting
index of every such occurrence in the vector <var>idx</var>.
</p>
<p>If there is no such occurrence, or if <var>pattern</var> is longer than
<var>str</var>, or if <var>pattern</var> itself is empty, then <var>idx</var> is the empty
array <code>[]</code>.
</p>
<p>The optional argument <code>&quot;overlaps&quot;</code> determines whether the pattern
can match at every position in <var>str</var> (true), or only for unique
occurrences of the complete pattern (false).  The default is true.
</p>
<p>If a cell array of strings <var>cellstr</var> is specified then <var>idx</var> is a
cell array of vectors, as specified above.
</p>
<p>The optional argument <code>&quot;forcecelloutput&quot;</code> forces <var>idx</var> to be
returned as a cell array of vectors.  The default is false.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">strfind (&quot;abababa&quot;, &quot;aba&quot;)
     &rArr; [1, 3, 5]
</pre><pre class="example">

</pre><pre class="example">strfind (&quot;abababa&quot;, &quot;aba&quot;, &quot;overlaps&quot;, false)
     &rArr; [1, 5]
</pre><pre class="example">

</pre><pre class="example">strfind ({&quot;abababa&quot;, &quot;bebebe&quot;, &quot;ab&quot;}, &quot;aba&quot;)
     &rArr;
        {
          [1,1] =

             1   3   5

          [1,2] = [](1x0)
          [1,3] = [](1x0)
        }
</pre><pre class="example">

</pre><pre class="example">strfind (&quot;abababa&quot;, &quot;aba&quot;, &quot;forcecelloutput&quot;, true)
     &rArr;
        {
          [1,1] =

             1   3   5
        }
</pre></div>

<p><strong>See also:</strong> <a href="#XREFregexp">regexp</a>, <a href="#XREFregexpi">regexpi</a>, <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>


<span id="XREFstrjoin"></span><dl>
<dt id="index-strjoin">: <em><var>str</var> =</em> <strong>strjoin</strong> <em>(<var>cstr</var>)</em></dt>
<dt id="index-strjoin-1">: <em><var>str</var> =</em> <strong>strjoin</strong> <em>(<var>cstr</var>, <var>delimiter</var>)</em></dt>
<dd><p>Join the elements of the cell string array, <var>cstr</var>, into a single
string.
</p>
<p>If no <var>delimiter</var> is specified, the elements of <var>cstr</var> are
separated by a space.
</p>
<p>If <var>delimiter</var> is specified as a string, the cell string array is
joined using the string.  Escape sequences are supported.
</p>
<p>If <var>delimiter</var> is a cell string array whose length is one less than
<var>cstr</var>, then the elements of <var>cstr</var> are joined by interleaving the
cell string elements of <var>delimiter</var>.  Escape sequences are not
supported.
</p>
<div class="example">
<pre class="example">strjoin ({'Octave','Scilab','Lush','Yorick'}, '*')
      &rArr; 'Octave*Scilab*Lush*Yorick'
</pre></div>

<p><strong>See also:</strong> <a href="#XREFstrsplit">strsplit</a>.
</p></dd></dl>


<span id="XREFstrmatch"></span><dl>
<dt id="index-strmatch">: <em></em> <strong>strmatch</strong> <em>(<var>s</var>, <var>A</var>)</em></dt>
<dt id="index-strmatch-1">: <em></em> <strong>strmatch</strong> <em>(<var>s</var>, <var>A</var>, &quot;exact&quot;)</em></dt>
<dd>
<p>This function is obsolete.  <strong>Use an alternative</strong> such as
<code>strncmp</code> or <code>strcmp</code> instead.
</p>
<p>Return indices of entries of <var>A</var> which begin with the string <var>s</var>.
</p>
<p>The second argument <var>A</var> must be a string, character matrix, or a cell
array of strings.
</p>
<p>If the third argument <code>&quot;exact&quot;</code> is not given, then <var>s</var> only
needs to match <var>A</var> up to the length of <var>s</var>.  Trailing spaces and
nulls in <var>s</var> and <var>A</var> are ignored when matching.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">strmatch (&quot;apple&quot;, &quot;apple juice&quot;)
     &rArr; 1

strmatch (&quot;apple&quot;, [&quot;apple  &quot;; &quot;apple juice&quot;; &quot;an apple&quot;])
     &rArr; [1; 2]

strmatch (&quot;apple&quot;, [&quot;apple  &quot;; &quot;apple juice&quot;; &quot;an apple&quot;], &quot;exact&quot;)
     &rArr; [1]
</pre></div>

<p><strong>Caution:</strong> <code>strmatch</code> is obsolete (and can produce incorrect
results in <small>MATLAB</small> when used with cell arrays of strings.  Use
<code>strncmp</code> (normal case) or <code>strcmp</code> (<code>&quot;exact&quot;</code> case) in all
new code.  Other replacement possibilities, depending on application,
include <code>regexp</code> or <code>validatestring</code>.
</p>
<p><strong>See also:</strong> <a href="Comparing-Strings.html#XREFstrncmp">strncmp</a>, <a href="Comparing-Strings.html#XREFstrcmp">strcmp</a>, <a href="#XREFregexp">regexp</a>, <a href="#XREFstrfind">strfind</a>, <a href="Validating-the-type-of-Arguments.html#XREFvalidatestring">validatestring</a>.
</p></dd></dl>


<span id="XREFstrtok"></span><dl>
<dt id="index-strtok">: <em>[<var>tok</var>, <var>rem</var>] =</em> <strong>strtok</strong> <em>(<var>str</var>)</em></dt>
<dt id="index-strtok-1">: <em>[<var>tok</var>, <var>rem</var>] =</em> <strong>strtok</strong> <em>(<var>str</var>, <var>delim</var>)</em></dt>
<dd>
<p>Find all characters in the string <var>str</var> up to, but not including, the
first character which is in the string <var>delim</var>.
</p>
<p><var>str</var> may also be a cell array of strings in which case the function
executes on every individual string and returns a cell array of tokens and
remainders.
</p>
<p>Leading delimiters are ignored.  If <var>delim</var> is not specified,
whitespace is assumed.
</p>
<p>If <var>rem</var> is requested, it contains the remainder of the string, starting
at the first delimiter.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">strtok (&quot;this is the life&quot;)
     &rArr; &quot;this&quot;

[tok, rem] = strtok (&quot;14*27+31&quot;, &quot;+-*/&quot;)
     &rArr;
        tok = 14
        rem = *27+31
</pre></div>

<p><strong>See also:</strong> <a href="#XREFindex">index</a>, <a href="#XREFstrsplit">strsplit</a>, <a href="#XREFstrchr">strchr</a>, <a href="Character-Class-Functions.html#XREFisspace">isspace</a>.
</p></dd></dl>


<span id="XREFstrsplit"></span><dl>
<dt id="index-strsplit">: <em>[<var>cstr</var>] =</em> <strong>strsplit</strong> <em>(<var>str</var>)</em></dt>
<dt id="index-strsplit-1">: <em>[<var>cstr</var>] =</em> <strong>strsplit</strong> <em>(<var>str</var>, <var>del</var>)</em></dt>
<dt id="index-strsplit-2">: <em>[<var>cstr</var>] =</em> <strong>strsplit</strong> <em>(&hellip;, <var>name</var>, <var>value</var>)</em></dt>
<dt id="index-strsplit-3">: <em>[<var>cstr</var>, <var>matches</var>] =</em> <strong>strsplit</strong> <em>(&hellip;)</em></dt>
<dd><p>Split the string <var>str</var> using the delimiters specified by <var>del</var> and
return a cell string array of substrings.
</p>
<p>If a delimiter is not specified the string is split at whitespace
<code>{&quot; &quot;, &quot;\f&quot;, &quot;\n&quot;, &quot;\r&quot;, &quot;\t&quot;, &quot;\v&quot;}</code>.  Otherwise, the delimiter,
<var>del</var> must be a string or cell array of strings.  By default,
consecutive delimiters in the input string <var>s</var> are collapsed into one
resulting in a single split.
</p>
<p>Supported <var>name</var>/<var>value</var> pair arguments are:
</p>
<ul>
<li> <var>collapsedelimiters</var> which may take the value of <code>true</code>
(default) or <code>false</code>.

</li><li> <var>delimitertype</var> which may take the value of <code>&quot;simple&quot;</code>
(default) or <code>&quot;regularexpression&quot;</code>.  A simple delimiter
matches the text exactly as written.  Otherwise, the syntax for regular
expressions outlined in <code>regexp</code> is used.
</li></ul>

<p>The optional second output, <var>matches</var>, returns the delimiters which were
matched in the original string.
</p>
<p>Examples with simple delimiters:
</p>
<div class="example">
<pre class="example">strsplit (&quot;a b c&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

strsplit (&quot;a,b,c&quot;, &quot;,&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

strsplit (&quot;a foo b,bar c&quot;, {&quot; &quot;, &quot;,&quot;, &quot;foo&quot;, &quot;bar&quot;})
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

strsplit (&quot;a,,b, c&quot;, {&quot;,&quot;, &quot; &quot;}, &quot;collapsedelimiters&quot;, false)
      &rArr;
          {
            [1,1] = a
            [1,2] =
            [1,3] = b
            [1,4] =
            [1,5] = c
          }

</pre></div>

<p>Examples with regularexpression delimiters:
</p>
<div class="example">
<pre class="example">strsplit (&quot;a foo b,bar c&quot;, ',|\s|foo|bar', ...
          &quot;delimitertype&quot;, &quot;regularexpression&quot;)
&rArr;
{
            [1,1] = a
            [1,2] = b
            [1,3] = c
}

strsplit (&quot;a,,b, c&quot;, '[, ]', &quot;collapsedelimiters&quot;, false, ...
          &quot;delimitertype&quot;, &quot;regularexpression&quot;)
&rArr;
{
            [1,1] = a
            [1,2] =
            [1,3] = b
            [1,4] =
            [1,5] = c
}

strsplit (&quot;a,\t,b, c&quot;, {',', '\s'}, &quot;delimitertype&quot;, &quot;regularexpression&quot;)
&rArr;
{
            [1,1] = a
            [1,2] = b
            [1,3] = c
}

strsplit (&quot;a,\t,b, c&quot;, {',', ' ', '\t'}, &quot;collapsedelimiters&quot;, false)
&rArr;
{
            [1,1] = a
            [1,2] =
            [1,3] =
            [1,4] = b
            [1,5] =
            [1,6] = c
}
</pre></div>


<p><strong>See also:</strong> <a href="#XREFostrsplit">ostrsplit</a>, <a href="#XREFstrjoin">strjoin</a>, <a href="#XREFstrtok">strtok</a>, <a href="#XREFregexp">regexp</a>.
</p></dd></dl>


<span id="XREFostrsplit"></span><dl>
<dt id="index-ostrsplit">: <em>[<var>cstr</var>] =</em> <strong>ostrsplit</strong> <em>(<var>s</var>, <var>sep</var>)</em></dt>
<dt id="index-ostrsplit-1">: <em>[<var>cstr</var>] =</em> <strong>ostrsplit</strong> <em>(<var>s</var>, <var>sep</var>, <var>strip_empty</var>)</em></dt>
<dd><p>Split the string <var>s</var> using one or more separators <var>sep</var> and return
a cell array of strings.
</p>
<p>Consecutive separators and separators at boundaries result in empty
strings, unless <var>strip_empty</var> is true.  The default value of
<var>strip_empty</var> is false.
</p>
<p>2-D character arrays are split at separators and at the original column
boundaries.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">ostrsplit (&quot;a,b,c&quot;, &quot;,&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

ostrsplit ([&quot;a,b&quot; ; &quot;cde&quot;], &quot;,&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = cde
          }
</pre></div>

<p><strong>See also:</strong> <a href="#XREFstrsplit">strsplit</a>, <a href="#XREFstrtok">strtok</a>.
</p></dd></dl>


<span id="XREFstrread"></span><dl>
<dt id="index-strread">: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>)</em></dt>
<dt id="index-strread-1">: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>, <var>format</var>)</em></dt>
<dt id="index-strread-2">: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>, <var>format</var>, <var>format_repeat</var>)</em></dt>
<dt id="index-strread-3">: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>, <var>format</var>, <var>prop1</var>, <var>value1</var>, &hellip;)</em></dt>
<dt id="index-strread-4">: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>, <var>format</var>, <var>format_repeat</var>, <var>prop1</var>, <var>value1</var>, &hellip;)</em></dt>
<dd>
<p>This function is obsolete.  Use <code>textscan</code> instead.
</p>
<p>Read data from a string.
</p>
<p>The string <var>str</var> is split into words that are repeatedly matched to the
specifiers in <var>format</var>.  The first word is matched to the first
specifier, the second to the second specifier and so forth.  If there are
more words than specifiers, the process is repeated until all words have
been processed.
</p>
<p>The string <var>format</var> describes how the words in <var>str</var> should be
parsed.  It may contain any combination of the following specifiers:
</p>
<dl compact="compact">
<dt><code>%s</code></dt>
<dd><p>The word is parsed as a string.
</p>
</dd>
<dt><code>%f</code></dt>
<dt><code>%n</code></dt>
<dd><p>The word is parsed as a number and converted to double.
</p>
</dd>
<dt><code>%d</code></dt>
<dt><code>%u</code></dt>
<dd><p>The word is parsed as a number and converted to int32.
</p>
</dd>
<dt><code>%*</code></dt>
<dt><code>%*f</code></dt>
<dt><code>%*s</code></dt>
<dd><p>The word is skipped.
</p>
<p>For %s and %d, %f, %n, %u and the associated %*s &hellip; specifiers an
optional width can be specified as %Ns, etc. where N is an integer &gt; 1.
For %f, format specifiers like %N.Mf are allowed.
</p>
</dd>
<dt><code>literals</code></dt>
<dd><p>In addition the format may contain literal character strings; these will be
skipped during reading.
</p></dd>
</dl>

<p>Parsed word corresponding to the first specifier are returned in the first
output argument and likewise for the rest of the specifiers.
</p>
<p>By default, <var>format</var> is <tt>&quot;%f&quot;</tt>, meaning that numbers are read from
<var>str</var>.  This will do if <var>str</var> contains only numeric fields.
</p>
<p>For example, the string
</p>
<div class="example">
<pre class="example"><var>str</var> = &quot;\
Bunny Bugs   5.5\n\
Duck Daffy  -7.5e-5\n\
Penguin Tux   6&quot;
</pre></div>

<p>can be read using
</p>
<div class="example">
<pre class="example">[<var>a</var>, <var>b</var>, <var>c</var>] = strread (<var>str</var>, &quot;%s %s %f&quot;);
</pre></div>

<p>Optional numeric argument <var>format_repeat</var> can be used for limiting the
number of items read:
</p>
<dl compact="compact">
<dt>-1</dt>
<dd><p>(default) read all of the string until the end.
</p>
</dd>
<dt>N</dt>
<dd><p>Read N times <var>nargout</var> items.  0 (zero) is an acceptable value for
<var>format_repeat</var>.
</p></dd>
</dl>

<p>The behavior of <code>strread</code> can be changed via property-value pairs.  The
following properties are recognized:
</p>
<dl compact="compact">
<dt><code>&quot;commentstyle&quot;</code></dt>
<dd><p>Parts of <var>str</var> are considered comments and will be skipped.
<var>value</var> is the comment style and can be any of the following.
</p>
<ul>
<li> <code>&quot;shell&quot;</code>
Everything from <code>#</code> characters to the nearest end-of-line is skipped.

</li><li> <code>&quot;c&quot;</code>
Everything between <code>/*</code> and <code>*/</code> is skipped.

</li><li> <code>&quot;c++&quot;</code>
Everything from <code>//</code> characters to the nearest end-of-line is skipped.

</li><li> <code>&quot;matlab&quot;</code>
Everything from <code>%</code> characters to the nearest end-of-line is skipped.

</li><li> user-supplied.  Two options:
(1) One string, or 1x1 cell string: Skip everything to the right of it;
(2) 2x1 cell string array: Everything between the left and right strings
is skipped.
</li></ul>

</dd>
<dt><code>&quot;delimiter&quot;</code></dt>
<dd><p>Any character in <var>value</var> will be used to split <var>str</var> into words
(default value = any whitespace).  Note that whitespace is implicitly added
to the set of delimiter characters unless a <code>&quot;%s&quot;</code> format conversion
specifier is supplied; see <code>&quot;whitespace&quot;</code> parameter below.  The set
of delimiter characters cannot be empty; if needed Octave substitutes a
space as delimiter.
</p>
</dd>
<dt><code>&quot;emptyvalue&quot;</code></dt>
<dd><p>Value to return for empty numeric values in non-whitespace delimited data.
The default is NaN.  When the data type does not support NaN (int32 for
example), then default is zero.
</p>
</dd>
<dt><code>&quot;multipledelimsasone&quot;</code></dt>
<dd><p>Treat a series of consecutive delimiters, without whitespace in between,
as a single delimiter.  Consecutive delimiter series need not be vertically
<code>&quot;aligned&quot;</code>.
</p>
</dd>
<dt><code>&quot;treatasempty&quot;</code></dt>
<dd><p>Treat single occurrences (surrounded by delimiters or whitespace) of the
string(s) in <var>value</var> as missing values.
</p>
</dd>
<dt><code>&quot;returnonerror&quot;</code></dt>
<dd><p>If <var>value</var> true (1, default), ignore read errors and return normally.
If false (0), return an error.
</p>
</dd>
<dt><code>&quot;whitespace&quot;</code></dt>
<dd><p>Any character in <var>value</var> will be interpreted as whitespace and trimmed;
the string defining whitespace must be enclosed in double quotes for proper
processing of special characters like <code>&quot;\t&quot;</code>.  In
each data field, multiple consecutive whitespace characters are collapsed
into one space and leading and trailing whitespace is removed.  The default
value for whitespace is
<code>&quot;
\b\r\n\t&quot;</code>
(note the space).  Whitespace is always added to the set of delimiter
characters unless at least one <code>&quot;%s&quot;</code> format conversion specifier is
supplied; in that case only whitespace explicitly specified in
<code>&quot;delimiter&quot;</code> is retained as delimiter and removed from the set of
whitespace characters.  If whitespace characters are to be kept as-is (in
e.g., strings), specify an empty value (i.e., <code>&quot;&quot;</code>) for
<code>&quot;whitespace&quot;</code>; obviously, whitespace cannot be a delimiter then.
</p>
</dd>
</dl>

<p>When the number of words in <var>str</var> doesn&rsquo;t match an exact multiple of
the number of format conversion specifiers, strread&rsquo;s behavior depends on
the last character of <var>str</var>:
</p>
<dl compact="compact">
<dt>last character = <code>&quot;\n&quot;</code></dt>
<dd><p>Data columns are padded with empty fields or NaN so that all columns have
equal length
</p>
</dd>
<dt>last character is not <code>&quot;\n&quot;</code></dt>
<dd><p>Data columns are not padded; strread returns columns of unequal length
</p>
</dd>
</dl>


<p><strong>See also:</strong> <a href="Simple-File-I_002fO.html#XREFtextscan">textscan</a>, <a href="Formatted-Input.html#XREFsscanf">sscanf</a>.
</p></dd></dl>


<span id="XREFstrrep"></span><dl>
<dt id="index-strrep">: <em><var>newstr</var> =</em> <strong>strrep</strong> <em>(<var>str</var>, <var>ptn</var>, <var>rep</var>)</em></dt>
<dt id="index-strrep-1">: <em><var>newstr</var> =</em> <strong>strrep</strong> <em>(<var>cellstr</var>, <var>ptn</var>, <var>rep</var>)</em></dt>
<dt id="index-strrep-2">: <em><var>newstr</var> =</em> <strong>strrep</strong> <em>(&hellip;, &quot;overlaps&quot;, <var>val</var>)</em></dt>
<dd><p>Replace all occurrences of the pattern <var>ptn</var> in the string <var>str</var>
with the string <var>rep</var> and return the result.
</p>
<p>The optional argument <code>&quot;overlaps&quot;</code> determines whether the pattern
can match at every position in <var>str</var> (true), or only for unique
occurrences of the complete pattern (false).  The default is true.
</p>
<p><var>s</var> may also be a cell array of strings, in which case the replacement
is done for each element and a cell array is returned.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">strrep (&quot;This is a test string&quot;, &quot;is&quot;, &quot;&amp;%$&quot;)
    &rArr;  &quot;Th&amp;%$ &amp;%$ a test string&quot;
</pre></div>


<p><strong>See also:</strong> <a href="#XREFregexprep">regexprep</a>, <a href="#XREFstrfind">strfind</a>.
</p></dd></dl>


<span id="XREFerase"></span><dl>
<dt id="index-erase">: <em><var>newstr</var> =</em> <strong>erase</strong> <em>(<var>str</var>, <var>ptn</var>)</em></dt>
<dd><p>Delete all occurrences of <var>ptn</var> within <var>str</var>.
</p>
<p><var>str</var> and <var>ptn</var> can be ordinary strings, cell array of strings, or
character arrays.
</p>
<p>Examples
</p>
<div class="example">
<pre class="example">## string, single pattern
erase (&quot;Hello World!&quot;, &quot; World&quot;)
    &rArr; &quot;Hello!&quot;

## cellstr, single pattern
erase ({&quot;Hello&quot;, &quot;World!&quot;}, &quot;World&quot;)
    &rArr; {&quot;Hello&quot;, &quot;!&quot;}

## string, multiple patterns
erase (&quot;The Octave interpreter is fabulous&quot;, ...
       {&quot;interpreter &quot;, &quot;The &quot;})
    &rArr; &quot;Octave is fabulous&quot;

## cellstr, multiple patterns
erase ({&quot;The &quot;, &quot;Octave interpreter &quot;, &quot;is fabulous&quot;}, ...
       {&quot;interpreter &quot;, &quot;The &quot;})
    &rArr; {&quot;&quot;, &quot;Octave &quot;, &quot;is fabulous&quot;}
</pre></div>

<p>Programming Note: <code>erase</code> deletes the first instance of a pattern in a
string when there are overlapping occurrences.  For example:
</p>
<div class="example">
<pre class="example">erase (&quot;abababa&quot;, &quot;aba&quot;)
    &rArr; &quot;b&quot;
</pre></div>

<p>See <code>strrep</code> for processing overlaps.
</p>

<p><strong>See also:</strong> <a href="#XREFstrrep">strrep</a>, <a href="#XREFregexprep">regexprep</a>.
</p></dd></dl>


<span id="XREFsubstr"></span><dl>
<dt id="index-substr">: <em></em> <strong>substr</strong> <em>(<var>s</var>, <var>offset</var>)</em></dt>
<dt id="index-substr-1">: <em></em> <strong>substr</strong> <em>(<var>s</var>, <var>offset</var>, <var>len</var>)</em></dt>
<dd><p>Return the substring of <var>s</var> which starts at character number
<var>offset</var> and is <var>len</var> characters long.
</p>
<p>Position numbering for offsets begins with 1.  If <var>offset</var> is negative,
extraction starts that far from the end of the string.
</p>
<p>If <var>len</var> is omitted, the substring extends to the end of <var>s</var>.  A
negative value for <var>len</var> extracts to within <var>len</var> characters of
the end of the string
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">substr (&quot;This is a test string&quot;, 6, 9)
     &rArr; &quot;is a test&quot;
substr (&quot;This is a test string&quot;, -11)
     &rArr; &quot;test string&quot;
substr (&quot;This is a test string&quot;, -11, -7)
     &rArr; &quot;test&quot;
</pre></div>

<p>This function is patterned after the equivalent function in Perl.
</p></dd></dl>


<span id="XREFregexp"></span><dl>
<dt id="index-regexp">: <em>[<var>s</var>, <var>e</var>, <var>te</var>, <var>m</var>, <var>t</var>, <var>nm</var>, <var>sp</var>] =</em> <strong>regexp</strong> <em>(<var>str</var>, <var>pat</var>)</em></dt>
<dt id="index-regexp-1">: <em>[&hellip;] =</em> <strong>regexp</strong> <em>(<var>str</var>, <var>pat</var>, &quot;<var>opt1</var>&quot;, &hellip;)</em></dt>
<dd><p>Regular expression string matching.
</p>
<p>Search for <var>pat</var> in UTF-8 encoded <var>str</var> and return the positions and
substrings of any matches, or empty values if there are none.
</p>
<p>The matched pattern <var>pat</var> can include any of the standard regex
operators, including:
</p>
<dl compact="compact">
<dt><code>.</code></dt>
<dd><p>Match any character
</p>
</dd>
<dt><code>* + ? {}</code></dt>
<dd><p>Repetition operators, representing
</p>
<dl compact="compact">
<dt><code>*</code></dt>
<dd><p>Match zero or more times
</p>
</dd>
<dt><code>+</code></dt>
<dd><p>Match one or more times
</p>
</dd>
<dt><code>?</code></dt>
<dd><p>Match zero or one times
</p>
</dd>
<dt><code>{<var>n</var>}</code></dt>
<dd><p>Match exactly <var>n</var> times
</p>
</dd>
<dt><code>{<var>n</var>,}</code></dt>
<dd><p>Match <var>n</var> or more times
</p>
</dd>
<dt><code>{<var>m</var>,<var>n</var>}</code></dt>
<dd><p>Match between <var>m</var> and <var>n</var> times
</p></dd>
</dl>

</dd>
<dt><code>[&hellip;] [^&hellip;]</code></dt>
<dd>
<p>List operators.  The pattern will match any character listed between
<code>&quot;[&quot;</code> and <code>&quot;]&quot;</code>.  If the first character is <code>&quot;^&quot;</code> then the
pattern is inverted and any character except those listed between brackets
will match.
</p>
<p>Escape sequences defined below can also be used inside list operators.  For
example, a template for a floating point number might be <code>[-+.\d]+</code>.
</p>
</dd>
<dt><code>() (?:)</code></dt>
<dd><p>Grouping operator.  The first form, parentheses only, also creates a token.
</p>
</dd>
<dt><code>|</code></dt>
<dd><p>Alternation operator.  Match one of a choice of regular expressions.  The
alternatives must be delimited by the grouping operator <code>()</code> above.
</p>
</dd>
<dt><code>^ $</code></dt>
<dd><p>Anchoring operators.  Requires pattern to occur at the start (<code>^</code>) or
end (<code>$</code>) of the string.
</p></dd>
</dl>

<p>In addition, the following escaped characters have special meaning.
</p>
<dl compact="compact">
<dt><code>\d</code></dt>
<dd><p>Match any digit
</p>
</dd>
<dt><code>\D</code></dt>
<dd><p>Match any non-digit
</p>
</dd>
<dt><code>\s</code></dt>
<dd><p>Match any whitespace character
</p>
</dd>
<dt><code>\S</code></dt>
<dd><p>Match any non-whitespace character
</p>
</dd>
<dt><code>\w</code></dt>
<dd><p>Match any word character
</p>
</dd>
<dt><code>\W</code></dt>
<dd><p>Match any non-word character
</p>
</dd>
<dt><code>\&lt;</code></dt>
<dd><p>Match the beginning of a word
</p>
</dd>
<dt><code>\&gt;</code></dt>
<dd><p>Match the end of a word
</p>
</dd>
<dt><code>\B</code></dt>
<dd><p>Match within a word
</p></dd>
</dl>

<p>Implementation Note: For compatibility with <small>MATLAB</small>, escape sequences
in <var>pat</var> (e.g., <code>&quot;\n&quot;</code> =&gt; newline) are expanded
even when <var>pat</var> has been defined with single quotes.  To disable
expansion use a second backslash before the escape sequence (e.g.,
&quot;\\n&quot;) or use the <code>regexptranslate</code>
function.
</p>
<p>The outputs of <code>regexp</code> default to the order given below
</p>
<dl compact="compact">
<dt><var>s</var></dt>
<dd><p>The start indices of each matching substring
</p>
</dd>
<dt><var>e</var></dt>
<dd><p>The end indices of each matching substring
</p>
</dd>
<dt><var>te</var></dt>
<dd><p>The extents of each matched token surrounded by <code>(&hellip;)</code> in
<var>pat</var>
</p>
</dd>
<dt><var>m</var></dt>
<dd><p>A cell array of the text of each match
</p>
</dd>
<dt><var>t</var></dt>
<dd><p>A cell array of the text of each token matched
</p>
</dd>
<dt><var>nm</var></dt>
<dd><p>A structure containing the text of each matched named token, with the name
being used as the fieldname.  A named token is denoted by
<code>(?&lt;name&gt;&hellip;)</code>.
</p>
</dd>
<dt><var>sp</var></dt>
<dd><p>A cell array of the text not returned by match, i.e., what remains if you
split the string based on <var>pat</var>.
</p></dd>
</dl>

<p>Particular output arguments, or the order of the output arguments, can be
selected by additional <var>opt</var> arguments.  These are strings and the
correspondence between the output arguments and the optional argument
are
</p>
<table>
<tr><td width="20%"></td><td width="30%"><code>'start'</code></td><td width="30%"><var>s</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'end'</code></td><td width="30%"><var>e</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'tokenExtents'</code></td><td width="30%"><var>te</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'match'</code></td><td width="30%"><var>m</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'tokens'</code></td><td width="30%"><var>t</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'names'</code></td><td width="30%"><var>nm</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'split'</code></td><td width="30%"><var>sp</var></td><td width="20%"></td></tr>
</table>

<p>Additional arguments are summarized below.
</p>
<dl compact="compact">
<dt>&lsquo;<samp>once</samp>&rsquo;</dt>
<dd><p>Return only the first occurrence of the pattern.
</p>
</dd>
<dt>&lsquo;<samp>matchcase</samp>&rsquo;</dt>
<dd><p>Make the matching case sensitive.  (default)
</p>
<p>Alternatively, use (?-i) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>ignorecase</samp>&rsquo;</dt>
<dd><p>Ignore case when matching the pattern to the string.
</p>
<p>Alternatively, use (?i) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>stringanchors</samp>&rsquo;</dt>
<dd><p>Match the anchor characters at the beginning and end of the string.
(default)
</p>
<p>Alternatively, use (?-m) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>lineanchors</samp>&rsquo;</dt>
<dd><p>Match the anchor characters at the beginning and end of the line.
</p>
<p>Alternatively, use (?m) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>dotall</samp>&rsquo;</dt>
<dd><p>The pattern <code>.</code> matches all characters including the newline character.
 (default)
</p>
<p>Alternatively, use (?s) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>dotexceptnewline</samp>&rsquo;</dt>
<dd><p>The pattern <code>.</code> matches all characters except the newline character.
</p>
<p>Alternatively, use (?-s) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>literalspacing</samp>&rsquo;</dt>
<dd><p>All characters in the pattern, including whitespace, are significant and are
used in pattern matching.  (default)
</p>
<p>Alternatively, use (?-x) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>freespacing</samp>&rsquo;</dt>
<dd><p>The pattern may include arbitrary whitespace and also comments beginning
with the character &lsquo;<samp>#</samp>&rsquo;.
</p>
<p>Alternatively, use (?x) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>noemptymatch</samp>&rsquo;</dt>
<dd><p>Zero-length matches are not returned.  (default)
</p>
</dd>
<dt>&lsquo;<samp>emptymatch</samp>&rsquo;</dt>
<dd><p>Return zero-length matches.
</p>
<p><code>regexp ('a', 'b*', 'emptymatch')</code> returns <code>[1 2]</code> because there
are zero or more <code>'b'</code> characters at positions 1 and end-of-string.
</p>
</dd>
</dl>

<p>Stack Limitation Note: Pattern searches are done with a recursive function
which can overflow the program stack when there are a high number of matches.
For example,
</p>
<div class="example">
<pre class="example"><code>regexp (repmat ('a', 1, 1e5), '(a)+')</code>
</pre></div>

<p>may lead to a segfault.  As an alternative, consider constructing pattern
searches that reduce the number of matches (e.g., by creatively using set
complement), and then further processing the return variables (now reduced in
size) with successive <code>regexp</code> searches.
</p>
<p><strong>See also:</strong> <a href="#XREFregexpi">regexpi</a>, <a href="#XREFstrfind">strfind</a>, <a href="#XREFregexprep">regexprep</a>.
</p></dd></dl>


<span id="XREFregexpi"></span><dl>
<dt id="index-regexpi">: <em>[<var>s</var>, <var>e</var>, <var>te</var>, <var>m</var>, <var>t</var>, <var>nm</var>, <var>sp</var>] =</em> <strong>regexpi</strong> <em>(<var>str</var>, <var>pat</var>)</em></dt>
<dt id="index-regexpi-1">: <em>[&hellip;] =</em> <strong>regexpi</strong> <em>(<var>str</var>, <var>pat</var>, &quot;<var>opt1</var>&quot;, &hellip;)</em></dt>
<dd>
<p>Case insensitive regular expression string matching.
</p>
<p>Search for <var>pat</var> in UTF-8 encoded <var>str</var> and return the positions and
substrings of any matches, or empty values if there are none.
See <a href="#XREFregexp">regexp</a>, for details on the syntax of the search pattern.
</p>
<p><strong>See also:</strong> <a href="#XREFregexp">regexp</a>.
</p></dd></dl>


<span id="XREFregexprep"></span><dl>
<dt id="index-regexprep">: <em><var>outstr</var> =</em> <strong>regexprep</strong> <em>(<var>string</var>, <var>pat</var>, <var>repstr</var>)</em></dt>
<dt id="index-regexprep-1">: <em><var>outstr</var> =</em> <strong>regexprep</strong> <em>(<var>string</var>, <var>pat</var>, <var>repstr</var>, &quot;<var>opt1</var>&quot;, &hellip;)</em></dt>
<dd><p>Replace occurrences of pattern <var>pat</var> in <var>string</var> with <var>repstr</var>.
</p>
<p>The pattern is a regular expression as documented for <code>regexp</code>.
See <a href="#XREFregexp">regexp</a>.
</p>
<p>All strings must be UTF-8 encoded.
</p>
<p>The replacement string may contain <code>$i</code>, which substitutes for the ith
set of parentheses in the match string.  For example,
</p>
<div class="example">
<pre class="example">regexprep (&quot;Bill Dunn&quot;, '(\w+) (\w+)', '$2, $1')
</pre></div>

<p>returns <code>&quot;Dunn, Bill&quot;</code>
</p>
<p>Options in addition to those of <code>regexp</code> are
</p>
<dl compact="compact">
<dt>&lsquo;<samp>once</samp>&rsquo;</dt>
<dd><p>Replace only the first occurrence of <var>pat</var> in the result.
</p>
</dd>
<dt>&lsquo;<samp>warnings</samp>&rsquo;</dt>
<dd><p>This option is present for compatibility but is ignored.
</p>
</dd>
</dl>

<p>Implementation Note: For compatibility with <small>MATLAB</small>, escape sequences
in <var>pat</var> (e.g., <code>&quot;\n&quot;</code> =&gt; newline) are expanded
even when <var>pat</var> has been defined with single quotes.  To disable
expansion use a second backslash before the escape sequence (e.g.,
&quot;\\n&quot;) or use the <code>regexptranslate</code>
function.
</p>
<p><strong>See also:</strong> <a href="#XREFregexp">regexp</a>, <a href="#XREFregexpi">regexpi</a>, <a href="#XREFstrrep">strrep</a>.
</p></dd></dl>


<span id="XREFregexptranslate"></span><dl>
<dt id="index-regexptranslate">: <em></em> <strong>regexptranslate</strong> <em>(<var>op</var>, <var>s</var>)</em></dt>
<dd><p>Translate a string for use in a regular expression.
</p>
<p>This may include either wildcard replacement or special character escaping.
</p>
<p>The behavior is controlled by <var>op</var> which can take the following
values
</p>
<dl compact="compact">
<dt><code>&quot;wildcard&quot;</code></dt>
<dd><p>The wildcard characters <code>.</code>, <code>*</code>, and <code>?</code> are replaced with
wildcards that are appropriate for a regular expression.  For example:
</p>
<div class="example">
<pre class="example">regexptranslate (&quot;wildcard&quot;, &quot;*.m&quot;)
     &rArr; '.*\.m'
</pre></div>

</dd>
<dt><code>&quot;escape&quot;</code></dt>
<dd><p>The characters <code>$.?[]</code>, that have special meaning for regular
expressions are escaped so that they are treated literally.  For example:
</p>
<div class="example">
<pre class="example">regexptranslate (&quot;escape&quot;, &quot;12.5&quot;)
     &rArr; '12\.5'
</pre></div>

</dd>
</dl>

<p><strong>See also:</strong> <a href="#XREFregexp">regexp</a>, <a href="#XREFregexpi">regexpi</a>, <a href="#XREFregexprep">regexprep</a>.
</p></dd></dl>


<span id="XREFuntabify"></span><dl>
<dt id="index-untabify">: <em></em> <strong>untabify</strong> <em>(<var>t</var>)</em></dt>
<dt id="index-untabify-1">: <em></em> <strong>untabify</strong> <em>(<var>t</var>, <var>tw</var>)</em></dt>
<dt id="index-untabify-2">: <em></em> <strong>untabify</strong> <em>(<var>t</var>, <var>tw</var>, <var>deblank</var>)</em></dt>
<dd><p>Replace TAB characters in <var>t</var> with spaces.
</p>
<p>The input, <var>t</var>, may be either a 2-D character array, or a cell array of
character strings.  The output is the same class as the input.
</p>
<p>The tab width is specified by <var>tw</var>, and defaults to eight.
</p>
<p>If the optional argument <var>deblank</var> is true, then the spaces will be
removed from the end of the character data.
</p>
<p>The following example reads a file and writes an untabified version of the
same file with trailing spaces stripped.
</p>
<div class="example">
<pre class="example">fid = fopen (&quot;tabbed_script.m&quot;);
text = char (fread (fid, &quot;uchar&quot;)');
fclose (fid);
fid = fopen (&quot;untabified_script.m&quot;, &quot;w&quot;);
text = untabify (strsplit (text, &quot;\n&quot;), 8, true);
fprintf (fid, &quot;%s\n&quot;, text{:});
fclose (fid);
</pre></div>


<p><strong>See also:</strong> <a href="String-Conversions.html#XREFstrjust">strjust</a>, <a href="#XREFstrsplit">strsplit</a>, <a href="#XREFdeblank">deblank</a>.
</p></dd></dl>


<span id="XREFunicode_005fidx"></span><dl>
<dt id="index-unicode_005fidx">: <em><var>idx</var> =</em> <strong>unicode_idx</strong> <em>(<var>str</var>)</em></dt>
<dd><p>Return an array with the indices for each UTF-8 encoded character in <var>str</var>.
</p>
<div class="example">
<pre class="example">unicode_idx (&quot;aäbc&quot;)
     &rArr; [1, 2, 2, 3, 4]
</pre></div>

</dd></dl>


<hr>
<div class="header">
<p>
Next: <a href="String-Conversions.html" accesskey="n" rel="next">String Conversions</a>, Previous: <a href="Comparing-Strings.html" accesskey="p" rel="prev">Comparing Strings</a>, Up: <a href="Strings.html" accesskey="u" rel="up">Strings</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>