regexpi - Match regular expression (case insensitive) (2024)

Match regular expression (case insensitive)

collapse all in page

Syntax

startIndex = regexpi(str,expression)

[startIndex,endIndex]= regexpi(str,expression)

out = regexpi(str,expression,outkey)

[out1,...,outN]= regexpi(str,expression,outkey1,...,outkeyN)

___ = regexpi(___,option1,...,optionM)

___ = regexpi(___,'forceCellOutput')

Description

startIndex = regexpi(str,expression) returnsthe starting index of each substring of str thatmatches the character patterns specified by the regular expression,without regard to letter case. If there are no matches, startIndex isan empty array.

example

[startIndex,endIndex]= regexpi(str,expression) returnsthe starting and ending indices of all matches.

out = regexpi(str,expression,outkey) returnsthe output specified by outkey. For example,if outkey is 'match', then regexpi returnsthe substrings that match the expression rather than their startingindices.

[out1,...,outN]= regexpi(str,expression,outkey1,...,outkeyN) returnsthe outputs specified by multiple output keywords, in the specifiedorder. For example, if you specify 'match','tokens',then regexpi returns substrings that match theentire expression and tokens thatmatch parts of the expression.

___ = regexpi(___,option1,...,optionM) modifiesthe search using the specified option flags. For example, specify 'matchcase' toperform a case-sensitive match. You can include any of the inputsand request any of the outputs from previous syntaxes.

example

___ = regexpi(___,'forceCellOutput') returnseach output argument as a scalar cell. The cells contain the numericarrays or substrings that are described as the outputs of the previoussyntaxes. You can include any of the inputs and request any of theoutputs from previous syntaxes.

Examples

collapse all

Pattern Matching

Open Live Script

Find words that start with c, end with t, and contain one or more vowels between them.

str = 'bat cat can car COAT court cut ct CAT-scan';expression = 'c[aeiou]+t';startIndex = regexpi(str,expression)
startIndex = 1×4 5 17 28 35

Values in startIndex indicate the index of the first character of each word that matches the regular expression.

The regular expression 'c[aeiou]+t' specifies this pattern:

  • c must be the first character.

  • c must be followed by one of the characters inside the brackets, [aeiou].

  • The bracketed pattern must occur one or more times, as indicated by the + operator.

  • t must be the last character, with no characters between the bracketed pattern and the t.

Case-Sensitive Match

Open Live Script

Match letter case in all or part of an expression.

By default, regexpi performs case-insensitive matching.

str = 'A character vector with UPPERCASE and lowercase text.';expression = '\w*case';matchStr = regexpi(str,expression,'match')
matchStr = 1x2 cell {'UPPERCASE'} {'lowercase'}

Use the regexp function with the same syntax as regexpi to perform case-sensitive matching.

matchWithRegexp = regexp(str,expression,'match')
matchWithRegexp = 1x1 cell array {'lowercase'}

To disable case-sensitive matching for regexp, use the 'ignorecase' option.

matchWithIgnorecase = regexp(str,expression,'match','ignorecase')
matchWithIgnorecase = 1x2 cell {'UPPERCASE'} {'lowercase'}

For multiple expressions, enable and disable case-insensitive matching for selected expressions using the (?i) and (?-i) search flags.

expression = {'(?-i)\w*case';... '(?i)\w*case'};matchStr = regexp(str,expression,'match');celldisp(matchStr)
 matchStr{1}{1} = lowercase matchStr{2}{1} = UPPERCASE matchStr{2}{2} = lowercase 

Input Arguments

collapse all

optionSearch option
'once' | 'warnings' | 'matchcase' | 'emptymatch' | 'dotexceptnewline' | 'lineanchors' | ...

Search option, specified as a character vector. Options come in pairs: one option that corresponds to the default behavior, and one option that allows you to override the default. Specify only one option from a pair. Options can appear in any order.

Default

Override

Description

'all'

'once'

Match the expression as many times as possible (default), or only once.

'nowarnings'

'warnings'

Suppress warnings (default), or display them.

'ignorecase'

'matchcase'

Ignore letter case (default), or match case.

'noemptymatch'

'emptymatch'

Ignore zero length matches (default), or include them.

'dotall'

'dotexceptnewline'

Match dot with any character (default), or all except newline (\n).

'stringanchors'

'lineanchors'

Apply ^ and $ metacharacters to the beginning and end of a character vector (default), or to the beginning and end of a line. The newline character (\n) specifies the end of a line. The beginning of a line is specified as the first character, or any character that immediately follows a newline character.

'literalspacing'

'freespacing'

Include space characters and comments when matching (default), or ignore them. With freespacing, use '\ ' and '\#' to match space and # characters.

Data Types: char

Output Arguments

collapse all

More About

collapse all

Tokens

Tokens are portions of the matched text thatcorrespond to portions of the regular expression. To create tokens,enclose part of the regular expression in parentheses.

For example, this expression finds a date of the form dd-mmm-yyyy,including tokens for the day, month, and year.

str = 'Here is a date: 01-Apr-2020';expression = '(\d+)-(\w+)-(\d+)';mydate = regexp(str,expression,'tokens');mydate{:}
ans = 1×3 cell array {'01'} {'Apr'} {'2020'}

You can associate names with tokens so that they are more easilyidentifiable:

str = 'Here is a date: 01-Apr-2020';expression = '(?<day>\d+)-(?<month>\w+)-(?<year>\d+)';mydate = regexp(str,expression,'names')
mydate = struct with fields: day: '01' month: 'Apr' year: '2020'

For more information, see Tokens in Regular Expressions.

Extended Capabilities

Version History

Introduced before R2006a

See Also

regexp | regexprep | regexptranslate | strfind | strjoin | strsplit | strrep | contains | replace

Topics

  • Lookahead Assertions in Regular Expressions
  • Dynamic Regular Expressions

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

regexpi - Match regular expression (case insensitive) (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

regexpi - Match regular expression (case insensitive) (2024)
Top Articles
How to disable Universal Plug and Play
How the Fed impacts stocks, crypto and other investments
Forozdz
Blorg Body Pillow
Jeremy Corbell Twitter
What to Serve with Lasagna (80+ side dishes and wine pairings)
Poe Pohx Profile
Produzione mondiale di vino
Athens Bucket List: 20 Best Things to Do in Athens, Greece
Sand Castle Parents Guide
Louisiana Sportsman Classifieds Guns
25Cc To Tbsp
R Cwbt
Tygodnik Polityka - Polityka.pl
Air Force Chief Results
I Saysopensesame
Healthier Homes | Coronavirus Protocol | Stanley Steemer - Stanley Steemer | The Steem Team
Menards Eau Claire Weekly Ad
Okc Body Rub
Yonkers Results For Tonight
Ceramic tiles vs vitrified tiles: Which one should you choose? - Building And Interiors
Deshuesadero El Pulpo
Mta Bus Forums
Miles City Montana Craigslist
Carroway Funeral Home Obituaries Lufkin
Jailfunds Send Message
Ofw Pinoy Channel Su
The Hoplite Revolution and the Rise of the Polis
Haley Gifts :: Stardew Valley
Weekly Math Review Q4 3
CVS Near Me | Somersworth, NH
Robeson County Mugshots 2022
Can You Buy Pedialyte On Food Stamps
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
The Closest Walmart From My Location
Final Jeopardy July 25 2023
“To be able to” and “to be allowed to” – Ersatzformen von “can” | sofatutor.com
Nail Salon Open On Monday Near Me
Umd Men's Basketball Duluth
Ladyva Is She Married
Rs3 Nature Spirit Quick Guide
Cleveland Save 25% - Lighthouse Immersive Studios | Buy Tickets
Craigslist Binghamton Cars And Trucks By Owner
Amy Zais Obituary
The Average Amount of Calories in a Poke Bowl | Grubby's Poke
Steam Input Per Game Setting
Msatlantathickdream
Where and How to Watch Sound of Freedom | Angel Studios
North Park Produce Poway Weekly Ad
Hcs Smartfind
Obituaries in Westchester, NY | The Journal News
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6584

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.