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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:13:14+00:00 2026-06-12T08:13:14+00:00

When sending a command to a modem, one usually sends a command (e.g. AT

  • 0

When sending a command to a modem, one usually sends a command (e.g. AT), followed by a \r. One then listens to the modem to see the result of the command, where this command itself is repeated. So a typical communication feedback from the modem looks like

AT\r\rOK\r\n

In case of an error it looks like

AT\r\rERROR\r\n

but in general, depending on the actual AT command, the returned value could be anything aside from OK and ERROR.

I would like to extract this response, i.e. a regular expression that returns me the OK, the ERROR or whatever the modem replies. Here are the conditions:

  • I want to verify the original command in the string, i.e. ATX\r\rOK\r\n should not match when the command was just AT.
  • I do not care about how many whitespace characters are present at all, the only thing I expect is to have a \n at the end. So AT\rOK\n and AT\nOK\r\r\n should match as well, but not AT\nOK\r\r.
  • Last, I do not care about extra stuff on the left side as long as they are separated from the AT command by whitespace characters. So OK\rAT\rOK\n should match (i.e. the right-side occurrence of OK), but XAT\rOK\r\n should not match.

Is it possible to do this with one single regex in order to extract the modem response, or do I need to make multiple regex searches? To see if the whole thing matches correctly at all, I might have found already an expression:

r = re.compile("\s+AT\s+\w+\s*\\n$")

But how to extract what the \w+ consists of?

  • 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-12T08:13:16+00:00Added an answer on June 12, 2026 at 8:13 am

    You put () around the part you want to extract, so your regex reads r"(?<!\S)AT\s+(\w+)\s*\n. You then get one group together with the match, that you can extract e.g. with group:

    r.search("yourText").group(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sending AT-Command to gsm modem through serial port. At the end of the
I'm trying to automate sending many jobs to a server using the qsub command.
In my previous question I had a problem with sending parameters over the command
Sending XML from C# Server and receiving it it in Android Java client This
I've developed an SMS app (send/receive SMS using GSM modem) using this library -
I have sending multiple parameters from my Checkbox Command. I have used a converter.
I am sending SMS by AT commands with GSM mobile phone. I wanna send
Sending the same pointer into two different shared_ptr 's is bad, it causes double
sending text to label and number to int from tabelview to viewcontroller but it
sending mail along with embedded image using asp.net I have already used following but

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.