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

  • Home
  • SEARCH
  • 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 8210763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:11:10+00:00 2026-06-07T10:11:10+00:00

I am trying to write a regex that will match the following YACC expression:

  • 0

I am trying to write a regex that will match the following YACC expression:
[left | right] || [top | bottom]:

It should match: (left or right) AND OR (top or bottom). OR ‘|‘ is simple to do but ‘||‘ I can’t figure it out.
This expression is part of a CSS gradient grammar defined by W3C:

<linear-gradient> = linear-gradient(
    [ [ <angle> | to <side-or-corner> ] ,]? 
    <color-stop>[, <color-stop>]+
)

<side-or-corner> = [left | right] || [top | bottom]

Edit:
Giving: left top
Matched: left top

Giving: left
Matched: left

Giving: right bottom
Matched: right bottom

Giving: right 20px
Matched: right

Hope this explains it better.
Thank you

  • 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-06-07T10:11:13+00:00Added an answer on June 7, 2026 at 10:11 am

    If I understood correctly, you want either a side (left/right/top/bottom) or a corner (top-left,bottom-right…).
    This can be solved as something like :

    /^((left|right|top|bottom)|((top|bottom)delimiter(left|right)))$/
    

    you can, of course, reverse the order of the sides for corner notation (to output corners as left-top and not top-left) :

    /^((left|right|top|bottom)|((left|right)delimiter(top|bottom)))$/
    

    Note that delimiter is your desired delimiter (can be an empty space or a minus sign).
    Hope this helps!

    P.S. : I heard your call for help on twitter :P.

    update
    based on your edit, I think now I understand what you need :

    /^((left|right|top|bottom)|((left|right|(-?\d*(\.\d+)?(px|em|\%)))\s+(top|bottom|(-?\d*(\.\d+)?(px|em|\%)))))$/   
    

    This regex now matches a side (left/top/right/bottom) or two sides defined by left & top values, which can be either the direction keywords (left/top/right/bottom) or an actual value (such as 100px or 1.4em).
    The value regex (-?\d*(\.\d+)?(px|em|\%)) matches any floating number (even without the first zero : .123 instead of 0.123) followed by a unit of measurement (here you can supply a full list of units)

    Here’s some of my (javascript) test which passed:

    var pattern = /^((left|right|top|bottom)|((left|right|(-?\d*(\.\d+)?(px|em|\%)))\s+(top|bottom|(-?\d*(\.\d+)?(px|em|\%)))))$/;
    pattern.test('left bottom');   // true
    pattern.test('-10px top');     // true
    pattern.test('-.23em 140%');   // true
    

    final update

    • removed the start & end characters
    • switched the order of the side and corner patterns, prioritizing the corner pattern to match first

    /(((left|right|(-?\d*(\.\d+)?(px|em|\%)))\s+(top|bottom|(-?\d*(\.\d+)?(px|em|\%))))|(left|right|top|bottom))/

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

Sidebar

Related Questions

I'm trying to write a regex that will match everything BUT an apostrophe that
I am trying to write a regex (in JavaScript) that will match a multi
I have been trying to write a regex that will remove whitespace following a
I'm trying to write a regular expression that will match the first 8 words
I am trying to write a regular expression that will match a string that
In java, I'm trying to write a regular expression that will match a unit
I'm trying to write a Regex that that will extract individual fields from a
I'm trying to write a regex to match any path that contains /? to
I'm trying to write a regex expression to match the src, width and height
I am trying to write a regex that will allow me to parse CSV

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.