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 4555854
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:17:04+00:00 2026-05-21T17:17:04+00:00

I am working on a little development language for my personal use. I do

  • 0

I am working on a little “development” language for my personal use. I do not plan to make it advanced at all (although I don’t know what will happen at later points), but I’ve run into a problem.

I am not very experienced with RegExp and I want to use it to check whatever a part of the code is defining a new variable or running function. In this case, I need a RegExp that will check if the user is defining a variable.

So, lets say I have a part like this: $abcd = 5

Now, the RegExp should meet the next criteria:
– It should check if the first letter is “$” (that’s easy: “\$”)
– Now, the letters after “$” (lets call them variable name) are the problem. Variable
name can contain letters [a-z, A-Z], numbers [0-9] and underscores [_]
– The next thing, space between the variable name and “=” can be infinitely long (it can
be one space ( ), or a millions of spaces – that should make no difference
– Than comes the equal sign (this is easy as well – “\=”)
– The same as in the third one applies for space after equal sign
– And at the end variable value. There should be no RegExp validation for this.

Thanks in advance!

  • 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-21T17:17:04+00:00Added an answer on May 21, 2026 at 5:17 pm

    You do not want to use regular expressions for a task like this. It will quickly turn into a nightmare. What you want is a simple grammar and a recursive-descent parser.

    That being said, something like this should work:

    /\$[a-zA-Z0-9_]+\s*=\s*[0-9]+$/
    

    This will only match cases where you’re assigning a number to variable. If you want to assign other values, you are going to have to make the regular expression more complicated (see what I meant about it turning into a nightmare? 🙂 ). For example, if you want to assign a string value to your variable, the regex will be different. You will also have to take into account things like escaped quotes and concatenation. Doing these things with a regular expression is very difficult.

    A simple grammar for function calls and variable definitions could look like this:

    <program>             ::= { <statement> }
    <statement>           ::= <function-call> | <variable-assignment>
    <function-call>       ::= <identifier>, '(', [ <parameter-list> ], ')'
    <identifier>          ::= <valid-starting-char>, { <valid-char> }
    <valid-starting-char> ::= [A-Za-z_]
    <valid-char>          ::= [A-Za-z]
    <parameter-list>      ::= <identifier>, { ',', <identifier> }
    <variable-assignment> ::= '$', <identifier>, '=', <value>
    <value>               ::= <number> | <string>
    <number>              ::= <digit>, { <digit> }
    <string>              ::= '"', ( { <character> | <escaped-character> } ), '"'
    <character>           ::= .
    <escaped-character>   ::= '\', <character>
    

    This grammar doesn’t take into account concatenation, numbers with fractional values (i.e., after the decimal point), and negative numbers. But it’s pretty simple and should give you a good starting point. There are many tutorials out there that tell you how to create a recursive-descent parser from an EBNF. You will still need to tokenize your input.

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

Sidebar

Related Questions

I thought people would be working on little code projects together, but I don't
I'm working on a little web crawler that will run in the system tray
I'm working on a little html/css framework that I can use for most of
I've been working a little with DevExpress CodeRush and Refactor! Pro this week, and
I'm trying to get this piece of code working a little better. I suspect
I'm working on a little test application at the minute and I have multiple
I'm working on a little web project that needs to keeps to a NumViews
I am working on a little Perl module and for some reason I had
I am working on a little pinball-game project for a hobby and am looking
I'm working on a little django app for reserving prints of paintings. Customers go

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.