Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:50:33+00:00 2026-05-29T22:50:33+00:00

I’m trying to write a single regular expression to convert all uppercase words to

  • 0

I’m trying to write a single regular expression to convert all uppercase words to lowercase while excluding uppercase Roman numerals from being converted.

The only way I found was to convert all uppercased words that are followed by a space, comma, or period, as well as hyphenated words into lowercase. Then convert all Roman numerals back to uppercase.

I used this to convert to lowercase:

(\u+[ ,.-])

Then I had to go through and find and replace all suspected Roman numerals.

What is a better way to do this? I tried negative lookahead expressions with no luck but I’m not very strong at writing them.

The sample that I’m testing this on is the U.S. Constitution. Here’s a sample of the input:

WE, the PEOPLE of the UNITED STATES, in order to form a more perfect
union, establish justice, ensure domestic tranquility, provide for the
common defence, promote the general welfare, and secure the blessings
of liberty to ourselves and our posterity, do ordain and establish
this Constitution for the United States of America.

ARTICLE I.

Sect. 1. ALL legislative powers, herein granted, shall be vested in a Congress of the United > States, which shall consist of a Senate and House of Representatives.

Sect. 2. The House of Representatives shall
be composed of Members chosen every second year by all the people of
the several States, and the Electors in each State shall have the
qualifications requisite for Electors of the most numerous branch of
the State Legislature. No person shall be a Representative who shall
not have attained to the age of twenty-five years, and been seven
years a citizen of the United States, and who shall not, when elected,
be an inhabitant of that State in which he shall be chosen.

ARTICLE IV.

ARTICLE V.

ARTICLE VI.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:50:34+00:00Added an answer on May 29, 2026 at 10:50 pm

    if the regex flavour supports negative lookaheads, you could try:

    \b(?![LXIVCDM]+\b)([A-Z]+)\b
    

    which says “any whole upper-case words that aren’t entirely composed of L, X, I, V, C, D, M” (the roman numerals).

    It also conveniently stops the word “I” from being converted. (As an aside, if you wanted to prevent one-letter capital words from being converted, use [A-Z]{2,} — this would prevent a capital “A” (at the start of a sentence) and I being converted, which you usually want to stay in their normal case).

    It would stop words consisting entirely of these letters being matched though — the only ones I can think of are “DID”, and perhaps “DIV” (as in HTML), “DIM” (as in dimension), “MID”, “MIDI”, “VIC” (as in Victoria?)…

    Although, you could certainly alter the roman numerals regex to be a little more considerate of the rules, e.g.

    (?=[MDCLXVI])M{0,3}(C[DM]|DC{0,3}|C{1,3})?(X[LC]|LX{0,3}|X{1,3})?(I[XV]|VI{0,3}|I{1,3})?
    

    Explanation:

    (?=[MDCLXVI])           # make sure we match at least something
                            # (since everything in this regex is optional)
    M{0,3}                  # Can have 0 to 3 Ms, being thousands
    (C[DM]|DC{0,3}|C{1,3})? # for the hundreds column can have CD, CM, 
                            # C, CC, CCC, D, DC, DCC, DCCC
    (X[LC]|LX{0,3}|X{1,3})? # for the tens column can have XL, XC, 
                            # L, LX, LXX, LXXX, X, XX, XXX
    (I[XV]|VI{0,3}|I{1,3})? # for the ones column can have IX, IV,
                            # V, VI, VII, VIII, I, II, III.
    

    I think that covers all possible roman numerals….

    If your regex flavour doesn’t support negative lookaheads, maybe you could do something like:

    \b((ROMAN_NUMERAL_REGEX)|([A-Z]+))\b
    

    And replace with “$2$3_converted_to_lower_case” (sorry – I don’t know how to do the actual conversion itself).

    The above would work because the regex only ever matches either the roman numeral regex (and is captured in $2), or the other regex (captured in $3). So one of $2 or $3 is always empty.

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

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.