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 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
  • 3 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'm preparing to embark on a web app development that will make little to
I'm working on a little program to make my life easier when using Microsoft
I'm working on a little WPF app that will run fullscreen and I'd like
I'm starting mobile development for my company, but i don't really know where to
I'm working through the book Beginning BlackBerry 7 Development and really putting my little
I'm working through the book Beginning BlackBerry 7 Development and really putting my little
I have a little problem and because my WEB development skills are not the
I've started working a little bit with lift+scala+mongorecord but I found a small annoyance
I'm working on a little Android app to stream some camera footage (as a
I'm working on a little project right now in ActionScript 3. The project is

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.