regex 如何在react native中删除html内容中的空格?

k4ymrczo  于 2023-08-08  发布在  React
关注(0)|答案(1)|浏览(87)

在我的项目中,我使用react native的WebView加载了一个html内容。但问题是我在结果中得到了不需要的字符。我的意思是html内容包含&nbsp,这些在react native中被渲染为一些不需要的字符沿着文本。我已经尝试过regex来删除它,但不起作用。下面是我的代码,请帮助。

编码

<Content contentContainerStyle={{ flex: 1}}>
     {this.state.data.map(item =>
       <View style={{flex:1,padding:10}}>
        <Text style={{textAlign:'center', margin:15,fontSize:20,fontWeight:'bold'}}>{item.data.course.name}</Text>
        <WebView
        source={{ html: item.data.description.replace(/^\s*&nbsp;/m, '') + htmlStyle }}
        javaScriptEnabled={true}
         />
         </View>
         )}
      </Content>

字符串
以下是截图


的数据

json

data:
course: {id: 5506, name: "Balance of Payment Account: Meaning and Significance"}
curriculum: false
description: "<p style="text-align: justify;"><strong>Guide to the module: </strong></p>↵<p style="text-align: justify;">              This module deals with the balance of payment account concepts from the Indian context. At the later part, a typical balance of payment scenario of India is illustrated by taking 2012-13 financial year as an example.</p>↵<p style="text-align: justify;"><strong>Balance of payment account</strong></p>↵<p style="text-align: justify;">           Balance of payment systematically shows the whole types of economic engagement between residents of India and the residents of the rest of the world. The transaction details are usually shown for a period (like one year).

2q5ifsrm

2q5ifsrm1#

以下操作将删除所有&nbsp;

replace(/(\r\n|\n|\r)/gm, '');

字符串

相关问题